X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=maint%2Fsynopsis-extractor;h=ecafe6771c26250f690b4cb3978bcc61f27144d8;hb=e225a4bdc7e2ca3d47266b8ec98135f521f727f3;hp=9390373033841e52b1476f41236ecfd2ddf319e6;hpb=ef48fc36a1f6dbf53867abf16e478fffe7889967;p=catagits%2FHTML-Zoom.git diff --git a/maint/synopsis-extractor b/maint/synopsis-extractor index 9390373..ecafe67 100755 --- a/maint/synopsis-extractor +++ b/maint/synopsis-extractor @@ -8,20 +8,18 @@ use File::Find; use File::Spec; sub slurp_file { - undef $/; - open(my $fh, '<', shift); - if(my $whole_file = <$fh>) { - return $whole_file; - } else { - return; - } + local (@ARGV, $/) = ($_[0]); <> } sub extract_synopsis { my $string = shift || return; my $head_or_cut = qr[head|cut]x; if($string=~m/^=head1 SYNOPSIS\n(.*?)^=$head_or_cut/sm) { - return $1; + my $extracted = $1; + my $begin_end = qr[begin|end]x; + $extracted=~s/\n^=$begin_end testinfo\n\n//smg; # remove test block + $extracted=~s/^\S.+?$//smg; # wipe out non code lines in pod + return $extracted; } else { return; } @@ -29,8 +27,7 @@ sub extract_synopsis { sub normalize_indent { my $extracted = shift || return; - - if($extracted=~m/([ \t]+)(\S+)/) { + if($extracted=~m/([ \t]+)(\S+)/) { $extracted=~s/^$1//gsm; return $extracted; } else { @@ -54,24 +51,27 @@ sub create_test_path_from_lib { return File::Spec->catfile($Bin, '..', 't', 'synopsis', lc($module_name).'.t'); } -sub create_or_update_test { - my ($string, $target) = @_; - return unless $string && $target; +sub create_or_update_test_file { + my ($target, $synopsis_string) = @_; + return unless $synopsis_string && $target; print "Writing $target\n"; open my $syn_test, '>', $target or die "Couldn't open $target - you screwed something up. Go fix it.\n"; - print $syn_test $string; + print $syn_test $synopsis_string; } -find(sub { - return unless $_=~/pm$/; - create_or_update_test( +sub wanted { + my $target_path = + create_test_path_from_lib $_; + my $synopsis_string = create_test_string normalize_indent extract_synopsis - slurp_file $File::Find::name, - create_test_path_from_lib($_), - ); -}, File::Spec->catfile($Bin, '..', 'lib')); + slurp_file $File::Find::name; + create_or_update_test_file + $target_path, + $synopsis_string, +} +find(\&wanted, File::Spec->catfile($Bin, '..', 'lib'));