From: tokuhirom Date: Tue, 30 Apr 2013 07:19:17 +0000 (+0900) Subject: Fixed `$metadata->contains_pod`. Because $#x is -1 origin. X-Git-Tag: v1.000012~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b50a98018a199717f2932fa763ae64967d4c3ee2;p=p5sagit%2FModule-Metadata.git Fixed `$metadata->contains_pod`. Because $#x is -1 origin. --- diff --git a/lib/Module/Metadata.pm b/lib/Module/Metadata.pm index 9f92dde..c66bd21 100644 --- a/lib/Module/Metadata.pm +++ b/lib/Module/Metadata.pm @@ -741,12 +741,12 @@ sub _evaluate_version_line { ############################################################ # accessors -sub name { $_[0]->{module} } +sub name { $_[0]->{module} } -sub filename { $_[0]->{filename} } -sub packages_inside { @{$_[0]->{packages}} } -sub pod_inside { @{$_[0]->{pod_headings}} } -sub contains_pod { $#{$_[0]->{pod_headings}} } +sub filename { $_[0]->{filename} } +sub packages_inside { @{$_[0]->{packages}} } +sub pod_inside { @{$_[0]->{pod_headings}} } +sub contains_pod { 0+@{$_[0]->{pod_headings}} } sub version { my $self = shift; diff --git a/t/contains_pod.t b/t/contains_pod.t new file mode 100644 index 0000000..3edfe43 --- /dev/null +++ b/t/contains_pod.t @@ -0,0 +1,49 @@ +use strict; +use warnings; +use Test::More tests => 3; +use Module::Metadata; + +{ + my $src = <<'...'; +package Foo; +1; +... + + open my $fh, '<', \$src; + my $module = Module::Metadata->new_from_handle($fh, 'Foo.pm'); + ok(!$module->contains_pod(), 'This module does not contains POD'); +} + +{ + my $src = <<'...'; +package Foo; +1; + +=head1 NAME + +Foo - bar +... + + open my $fh, '<', \$src; + my $module = Module::Metadata->new_from_handle($fh, 'Foo.pm'); + ok($module->contains_pod(), 'This module contains POD'); +} + +{ + my $src = <<'...'; +package Foo; +1; + +=head1 NAME + +Foo - bar + +=head1 AUTHORS + +Tokuhiro Matsuno +... + + open my $fh, '<', \$src; + my $module = Module::Metadata->new_from_handle($fh, 'Foo.pm'); + ok($module->contains_pod(), 'This module contains POD'); +}