From: Jesse Luehrs Date: Tue, 6 Sep 2011 01:02:22 +0000 (-0500) Subject: tests, and make this actually work X-Git-Tag: 0.32~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=12b5662ca1ca213389b3d4af99f8616b2129f0cc;p=gitmo%2FPackage-Stash.git tests, and make this actually work --- diff --git a/lib/Package/Stash/PP.pm b/lib/Package/Stash/PP.pm index 408f3be..247a3b8 100644 --- a/lib/Package/Stash/PP.pm +++ b/lib/Package/Stash/PP.pm @@ -40,7 +40,7 @@ sub new { . "currently support anonymous stashes. You should install " . "Package::Stash::XS"; } - elsif ($package !~ /[0-9A-Z_a-z]+(?:::[0-9A-Z_a-z]+)*/) { + elsif ($package !~ /\A[0-9A-Z_a-z]+(?:::[0-9A-Z_a-z]+)*\z/) { confess "$package is not a module name"; } diff --git a/t/basic.t b/t/basic.t index a106e9e..f20e055 100644 --- a/t/basic.t +++ b/t/basic.t @@ -417,4 +417,24 @@ like(exception { ); } +for my $package ('Foo:Bar', 'Foo/Bar', 'Foo Bar', 'Foo:::Bar', '') { + like( + exception { Package::Stash->new($package) }, + qr/^$package is not a module name/, + "$package is not a module name" + ); +} + +like( + exception { Package::Stash->new([]) }, + qr/^Package::Stash->new must be passed the name of the package to access/, + "module name must be a string" +); + +like( + exception { Package::Stash->new(undef) }, + qr/^Package::Stash->new must be passed the name of the package to access/, + "module name must be a string" +); + done_testing;