diff options
author | Kenichi Ishigaki <charsbar@users.noreply.github.com> | 2016-11-03 21:39:40 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-03 21:39:40 +0900 |
commit | bed9903ab2560df04de6b271792cca97b66a281c (patch) | |
tree | fa7c63c1dd84be7587cc495d0cc6ba1af59f685a | |
parent | 72cb5be790612fa0c7395706f30acbe97b9ec22f (diff) | |
parent | dbcefc108294e2329ff4cafa7a84d8fb3abbae9f (diff) |
Merge pull request #9 from rhalliday/provides_package_single_quote
Add global modifier to package name substitution
-rw-r--r-- | lib/Parse/PMFile.pm | 2 | ||||
-rw-r--r-- | t/41_multiple_packages.t | 52 |
2 files changed, 53 insertions, 1 deletions
diff --git a/lib/Parse/PMFile.pm b/lib/Parse/PMFile.pm index f77cc6d..98894b3 100644 --- a/lib/Parse/PMFile.pm +++ b/lib/Parse/PMFile.pm @@ -397,7 +397,7 @@ sub _packages_per_pmfile { # Found something # from package - $pkg =~ s/\'/::/; + $pkg =~ s/\'/::/g; next PLINE unless $pkg =~ /^[A-Za-z]/; next PLINE unless $pkg =~ /\w$/; next PLINE if $pkg eq "main"; diff --git a/t/41_multiple_packages.t b/t/41_multiple_packages.t new file mode 100644 index 0000000..6cb7ec0 --- /dev/null +++ b/t/41_multiple_packages.t @@ -0,0 +1,52 @@ +use strict; +use warnings; +use Test::More; +use Parse::PMFile; +use File::Temp; + +my $tmpdir = File::Temp->newdir(CLEANUP => 1); +plan skip_all => "tmpdir is not ready" unless -e $tmpdir && -w $tmpdir; + +my $pmfile = "$tmpdir/Test.pm"; +my @package = (qw/Parse PMFile Test/); +my @subpackages = (qw/Location Blah Thing/); + +my $parser = Parse::PMFile->new; +subtest 'arisdottle' => sub { + _generate_package(q{::}); + my $info = $parser->parse($pmfile); + _check_packages($info); +}; + +subtest 'quote' => sub { + _generate_package(q{'}); + my $info = $parser->parse($pmfile); + _check_packages($info); +}; + +done_testing; + +sub _generate_package { + my ($sep) = @_; + my $version = 1; + + open my $fh, '>', $pmfile or plan skip_all => "Failed to create a pmfile"; + print $fh 'package ' . join($sep, @package) . ";\n"; + print $fh q{our $VERSION = '1.0} . $version++ . "';\n1;\n"; + for my $subpackage (@subpackages) { + print $fh 'package ' . join($sep, @package, $subpackage) . ";\n"; + print $fh q{our $VERSION = '1.0} . $version++ . "';\n1;\n"; + } + close $fh; +} + +sub _check_packages { + my ($info) = @_; + + my $package = join(q{::}, @package); + ok exists $info->{$package}, q{found base package}; + + for my $subpackage (@subpackages) { + ok exists $info->{$package . q{::} . $subpackage}, qq{found sub package $subpackage}; + } +} |