Skip to content

Instantly share code, notes, and snippets.

@ryochin
Created June 27, 2013 08:14
Show Gist options
  • Save ryochin/5874798 to your computer and use it in GitHub Desktop.
Save ryochin/5874798 to your computer and use it in GitHub Desktop.
split perl source/pod to save to Mod.pm/Mod.pod
#!/usr/bin/env perl
# split perl source/pod to save to Mod.pm/Mod.pod
use strict;
use warnings;
use Path::Class qw(file);
use Pod::Clipper;
my $file = shift @ARGV or die "usage: $0 <perl module file>";
my $clipper = Pod::Clipper->new( { data => scalar file( $file )->slurp } );
my @pod;
my @source;
for my $block( @{ $clipper->all} ){
if( $block->is_pod ){
push @pod, $block->data;
}
else {
push @source, $block->data;
}
}
# save pod
do {
my $pod = join "\n\n", @pod;
$pod =~ s{^=pod\n+}{}sm;
$pod =~ s{=cut\n\n=pod\n\n}{}smg;
$pod =~ s{\n+=cut$}{\n}s;
my $fh = file("./Mod.pod")->openw;
$fh->print( $pod );
$fh->close;
};
# save source
do {
my $fh = file("./Mod.pm")->openw;
$fh->print( join "", @source );
$fh->close;
};
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment