From: Vincent Pit Date: Mon, 30 Jul 2012 16:38:13 +0000 (+0200) Subject: Be stricter about which =XXX are POD keywords X-Git-Tag: release_1.0.10_001~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a4aafbc2;p=p5sagit%2FModule-Metadata.git Be stricter about which =XXX are POD keywords --- diff --git a/lib/Module/Metadata.pm b/lib/Module/Metadata.pm index 10c8e68..e5910d0 100644 --- a/lib/Module/Metadata.pm +++ b/lib/Module/Metadata.pm @@ -61,6 +61,9 @@ my $VERS_REGEXP = qr{ # match a VERSION definition =[^=~] # = but not ==, nor =~ }x; +my $PODSECT_REGEXP = qr{ + ^=(cut|pod|head[1-4]|over|item|back|begin|end|for|encoding)\b +}x; sub new_from_file { my $class = shift; @@ -498,7 +501,7 @@ sub _parse_fh { chomp( $line ); my $is_cut; - if ( $line =~ /^=(.{0,3})/ ) { + if ( $line =~ /$PODSECT_REGEXP/o ) { $is_cut = $1 eq 'cut'; $in_pod = !$is_cut; } @@ -508,7 +511,7 @@ sub _parse_fh { if ( $in_pod ) { - if ( $line =~ /^=head\d\s+(.+)\s*$/ ) { + if ( $line =~ /^=head[1-4]\s+(.+)\s*$/ ) { push( @pod, $1 ); if ( $self->{collect_pod} && length( $pod_data ) ) { $pod{$pod_sect} = $pod_data; diff --git a/t/metadata.t b/t/metadata.t index 942cc62..a0bcaaa 100644 --- a/t/metadata.t +++ b/t/metadata.t @@ -212,7 +212,7 @@ package Simple v1.2.3_4 { ); my %modules = reverse @modules; -plan tests => 52 + 2 * keys( %modules ); +plan tests => 54 + 2 * keys( %modules ); require_ok('Module::Metadata'); @@ -499,6 +499,31 @@ EXPECTED } { + # test things that look like POD, but aren't +$dist->change_file( 'lib/Simple.pm', <<'---' ); +package Simple; +sub podzol () { 1 } +sub cute () { 2 } +my $x +=podzol +; + +our $VERSION = '1.23'; + +my $y +=cute +; + +our $VERSION = '999'; + +--- + $dist->regen; + $pm_info = Module::Metadata->new_from_file('lib/Simple.pm'); + is( $pm_info->name, 'Simple', 'found default package' ); + is( $pm_info->version, '1.23', 'version for default package' ); +} + +{ # Make sure processing stops after __DATA__ $dist->change_file( 'lib/Simple.pm', <<'---' ); package Simple;