1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
use strict;
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 @versioncaller;
my $version;
BEGIN {
package CheckFile;
$INC{"CheckFile.pm"} = __FILE__;
sub import {
@importcaller = caller;
}
sub VERSION {
$version = $_[1];
@versioncaller = caller;
}
}
BEGIN {
package MultiExporter;
$INC{"MultiExporter.pm"} = __FILE__;
use Import::Into;
sub import {
my $target = caller;
warnings->import::into($target);
MyExporter->import::into($target, 'thing');
CheckFile->import::into(1);
}
}
eval q{
package TestPackage;
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();
}, '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';
is scalar @versioncaller, 0, 'VERSION not called when not specified';
@importcaller = ();
@versioncaller = ();
$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 $versioncaller[0], 'ExplicitPackage',
'VERSION with hash has correct package';
is $versioncaller[1], 'explicit-file.pl',
'VERSION with hash has correct file';
is $versioncaller[2], 42,
'VERSION 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,
});
}
}
@importcaller = ();
@versioncaller = ();
$version = undef;
eval q{
package ExplicitLevel;
#line 42 "explicit-level.pl"
use LevelExporter;
1;
} or die $@;
is $importcaller[0], 'ExplicitLevel',
'import with level in hash has correct package';
is $importcaller[1], 'explicit-level.pl',
'import with level in hash has correct file';
is $importcaller[2], 42,
'import with level in hash has correct line';
is $versioncaller[0], 'ExplicitLevel',
'VERSION with level in hash has correct package';
is $versioncaller[1], 'explicit-level.pl',
'VERSION with level in hash has correct file';
is $versioncaller[2], 42,
'VERSION with level in hash has correct line';
is $version, 219,
'import with level in hash has correct version';
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" );
|