Extract the Synopsis of a Module

Posted in: Technical Track

When I begin to work with a module, most of the time what I do is to look at its pod, and copy the code in the synopsis that I’ll use as a a baseline.

Open pod, copy, paste. That’s a lot of exhausting work… While I’m pretty sure there’s already a better tool to do it somewhere in CPAN, here’s my little podsyn script that does all the hard work for me.

#!/usr/bin/env perl
use strict;
use warnings;
use Pod::Find qw/ pod_where /;
use Pod::XML;
use XML::LibXML;
my $module = shift or die "usage: $0 <module>\n";
my $xml = do {
    local *STDOUT;
    open STDOUT, '>', \my $stdout;
    Pod::XML->new->parse_from_file( pod_where( { -inc => 1 }, $module ) );
$xml =~ s/xmlns=".*?"//;
print XML::LibXML->load_xml( string => $xml )

Its use on the command line is straigt-forward:

$ ./files/podsyn.pl Pod::XML
use Pod::XML;
my $parser = Pod::XML->new();

And crafting a vim command to do the same shouldn’t be too hard either (I’ll try to post one as soon as my vim-fu comes back to me).

Want to talk with an expert? Schedule a call with our team to get the conversation started.

No comments

Leave a Reply

Your email address will not be published. Required fields are marked *