X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FImport-Into.git;a=blobdiff_plain;f=t%2Fimport_into.t;h=12b200b08d94da8ae7eced7cdb8dcc74bfee30c2;hp=bc323fb795a1d16d90b6e69d1823a7e0a8bd7976;hb=a6e3c44c68290b6b3f7a6aee792fffa5085f5151;hpb=1615d435a41a6924d7a853bcbadd470fc5039fc3 diff --git a/t/import_into.t b/t/import_into.t index bc323fb..12b200b 100644 --- a/t/import_into.t +++ b/t/import_into.t @@ -3,16 +3,33 @@ use warnings FATAL => 'all'; use Test::More qw(no_plan); BEGIN { - package MyExporter; + $INC{"MyExporter.pm"} = __FILE__; use base qw(Exporter); our @EXPORT_OK = qw(thing); sub thing { 'thing' } +} + +my @importcaller; +my $version; +BEGIN { + package CheckFile; + $INC{"CheckFile.pm"} = __FILE__; + sub import { + @importcaller = caller; + } + sub VERSION { + $version = $_[1]; + } +} + +BEGIN { package MultiExporter; + $INC{"MultiExporter.pm"} = __FILE__; use Import::Into; @@ -20,31 +37,72 @@ BEGIN { my $target = caller; warnings->import::into($target); MyExporter->import::into($target, 'thing'); + CheckFile->import::into(1); } - - $INC{"MultiExporter.pm"} = 1; } -BEGIN { - +eval q{ package TestPackage; - no warnings; + no warnings FATAL => 'all'; +#line 1 "import_into_inline.pl" use MultiExporter; sub test { thing . undef } -} + 1; +} or die $@; my @w; is(do { local $SIG{__WARN__} = sub { push @w, @_; }; - TestPackage::test; + TestPackage::test(); }, 'thing', 'returned thing ok'); is(scalar @w, 1, 'Only one entry in @w'); like($w[0], qr/uninitialized/, 'Correct warning'); + +is $importcaller[0], 'TestPackage', + 'import by level has correct package'; +is $importcaller[1], 'import_into_inline.pl', + 'import by level has correct file'; +is $importcaller[2], 1, + 'import by level has correct line'; + +@importcaller = (); +$version = undef; +CheckFile->import::into({ + package => 'ExplicitPackage', + filename => 'explicit-file.pl', + line => 42, + version => 219, +}); + +is $importcaller[0], 'ExplicitPackage', + 'import with hash has correct package'; +is $importcaller[1], 'explicit-file.pl', + 'import with hash has correct file'; +is $importcaller[2], 42, + 'import with hash has correct line'; +is $version, 219, + 'import with hash has correct version'; + +BEGIN { + package LevelExporter; + $INC{'LevelExporter.pm'} = __FILE__; + + sub import { + CheckFile->import::into({ + level => 1, + version => 219, + }); + } +} + +ok( !IPC::Open3->can("open3"), "IPC::Open3 is unloaded" ); +IPC::Open3->import::into("TestPackage"); +ok( TestPackage->can("open3"), "IPC::Open3 was use'd and import::into'd" );