our $VERSION;
$VERSION = '1.23';
---
+ '1.23' => <<'---', # commented & defined on same line
+package Simple;
+our $VERSION = '1.23'; # our $VERSION = '4.56';
+---
+ '1.23' => <<'---', # commented & defined on separate lines
+package Simple;
+# our $VERSION = '4.56';
+our $VERSION = '1.23';
+---
'1.23' => <<'---', # use vars
package Simple;
use vars qw( $VERSION );
);
my %modules = reverse @modules;
-plan tests => 42 + 2 * keys( %modules );
+plan tests => 54 + 2 * keys( %modules );
require_ok('Module::Metadata');
ok( defined( $pm_info ), 'new_from_handle() succeeds' );
$pm_info = Module::Metadata->new_from_handle( $handle );
is( $pm_info, undef, "new_from_handle() without filename returns undef" );
-
+close($handle);
# construct from module name, using custom include path
$pm_info = Module::Metadata->new_from_module(
Simple Simon
+You can find me on the IRC channel
+#simon on irc.perl.org.
+
=cut
---
$dist->regen;
$pm_info = Module::Metadata->new_from_module(
$dist->name, inc => [ 'lib', @INC ], collect_pod => 1 );
-my $name = $pm_info->pod('NAME');
-if ( $name ) {
- $name =~ s/^\s+//;
- $name =~ s/\s+$//;
+{
+ my %pod;
+ for my $section (qw(NAME AUTHOR)) {
+ my $content = $pm_info->pod( $section );
+ if ( $content ) {
+ $content =~ s/^\s+//;
+ $content =~ s/\s+$//;
+ }
+ $pod{$section} = $content;
+ }
+ my %expected = (
+ NAME => q|Simple - It's easy.|,
+ AUTHOR => <<'EXPECTED'
+Simple Simon
+
+You can find me on the IRC channel
+#simon on irc.perl.org.
+EXPECTED
+ );
+ for my $text (values %expected) {
+ $text =~ s/^\s+//;
+ $text =~ s/\s+$//;
+ }
+ is( $pod{NAME}, $expected{NAME}, 'collected NAME pod section' );
+ is( $pod{AUTHOR}, $expected{AUTHOR}, 'collected AUTHOR pod section' );
}
-is( $name, q|Simple - It's easy.|, 'collected pod section' );
+{
+ # 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__
is_deeply( $got_provides, $exp_provides, "provides()" )
or diag explain $got_provides;
}
+
+# Check package_versions_from_directory with regard to case-sensitivity
+{
+ $dist->change_file( 'lib/Simple.pm', <<'---' );
+package simple;
+$VERSION = '0.01';
+---
+ $dist->regen;
+
+ $pm_info = Module::Metadata->new_from_file('lib/Simple.pm');
+ is( $pm_info->name, undef, 'no default package' );
+ is( $pm_info->version, undef, 'version for default package' );
+ is( $pm_info->version('simple'), '0.01', 'version for lower-case package' );
+ is( $pm_info->version('Simple'), undef, 'version for capitalized package' );
+
+ $dist->change_file( 'lib/Simple.pm', <<'---' );
+package simple;
+$VERSION = '0.01';
+package Simple;
+$VERSION = '0.02';
+package SiMpLe;
+$VERSION = '0.03';
+---
+ $dist->regen;
+
+ $pm_info = Module::Metadata->new_from_file('lib/Simple.pm');
+ is( $pm_info->name, 'Simple', 'found default package' );
+ is( $pm_info->version, '0.02', 'version for default package' );
+ is( $pm_info->version('simple'), '0.01', 'version for lower-case package' );
+ is( $pm_info->version('Simple'), '0.02', 'version for capitalized package' );
+ is( $pm_info->version('SiMpLe'), '0.03', 'version for mixed-case package' );
+}