use File::Spec;
sub slurp_file {
- undef $/;
- open(my $fh, '<', shift) || return;
- if(my $whole_file = <$fh>) {
- return $whole_file;
- } else {
- return;
- }
+ local (@ARGV, $/) = ($_[0]); <>
}
sub extract_synopsis {
my $head_or_cut = qr[head|cut]x;
if($string=~m/^=head1 SYNOPSIS\n(.*?)^=$head_or_cut/sm) {
my $extracted = $1;
- $extracted=~s/^\S.+?$//m; # wipe out non code lines in pod
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;
print $syn_test $synopsis_string;
}
-find sub {
-
+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_or_update_test_file
$target_path,
$synopsis_string,
+}
-}, File::Spec->catfile($Bin, '..', 'lib');
-
+find(\&wanted, File::Spec->catfile($Bin, '..', 'lib'));