Commit | Line | Data |
2afb5246 |
1 | use strict; |
2 | use warnings FATAL => 'all'; |
1615d435 |
3 | use Test::More qw(no_plan); |
2afb5246 |
4 | |
5 | BEGIN { |
2afb5246 |
6 | package MyExporter; |
a6e3c44c |
7 | $INC{"MyExporter.pm"} = __FILE__; |
2afb5246 |
8 | |
9 | use base qw(Exporter); |
10 | |
11 | our @EXPORT_OK = qw(thing); |
12 | |
13 | sub thing { 'thing' } |
a6e3c44c |
14 | } |
15 | |
16 | my @importcaller; |
7a9ec1de |
17 | my @versioncaller; |
a6e3c44c |
18 | my $version; |
19 | BEGIN { |
20 | package CheckFile; |
21 | $INC{"CheckFile.pm"} = __FILE__; |
2afb5246 |
22 | |
a6e3c44c |
23 | sub import { |
24 | @importcaller = caller; |
25 | } |
26 | sub VERSION { |
27 | $version = $_[1]; |
7a9ec1de |
28 | @versioncaller = caller; |
a6e3c44c |
29 | } |
30 | } |
cc087979 |
31 | |
a6e3c44c |
32 | BEGIN { |
2afb5246 |
33 | package MultiExporter; |
a6e3c44c |
34 | $INC{"MultiExporter.pm"} = __FILE__; |
2afb5246 |
35 | |
36 | use Import::Into; |
37 | |
38 | sub import { |
39 | my $target = caller; |
40 | warnings->import::into($target); |
41 | MyExporter->import::into($target, 'thing'); |
e5f9555d |
42 | CheckFile->import::into(1); |
2afb5246 |
43 | } |
e5f9555d |
44 | } |
45 | |
8afc1658 |
46 | eval q{ |
2afb5246 |
47 | package TestPackage; |
48 | |
b95fe8b9 |
49 | no warnings FATAL => 'all'; |
2afb5246 |
50 | |
8afc1658 |
51 | #line 1 "import_into_inline.pl" |
2afb5246 |
52 | use MultiExporter; |
53 | |
54 | sub test { |
55 | thing . undef |
56 | } |
8afc1658 |
57 | 1; |
58 | } or die $@; |
2afb5246 |
59 | |
60 | my @w; |
61 | |
62 | is(do { |
63 | local $SIG{__WARN__} = sub { push @w, @_; }; |
8afc1658 |
64 | TestPackage::test(); |
2afb5246 |
65 | }, 'thing', 'returned thing ok'); |
66 | |
67 | is(scalar @w, 1, 'Only one entry in @w'); |
68 | |
69 | like($w[0], qr/uninitialized/, 'Correct warning'); |
e5f9555d |
70 | |
a6e3c44c |
71 | is $importcaller[0], 'TestPackage', |
72 | 'import by level has correct package'; |
73 | is $importcaller[1], 'import_into_inline.pl', |
74 | 'import by level has correct file'; |
75 | is $importcaller[2], 1, |
76 | 'import by level has correct line'; |
7a9ec1de |
77 | is scalar @versioncaller, 0, 'VERSION not called when not specified'; |
568eef3e |
78 | |
a6e3c44c |
79 | @importcaller = (); |
7a9ec1de |
80 | @versioncaller = (); |
a6e3c44c |
81 | $version = undef; |
568eef3e |
82 | CheckFile->import::into({ |
83 | package => 'ExplicitPackage', |
84 | filename => 'explicit-file.pl', |
85 | line => 42, |
86 | version => 219, |
87 | }); |
88 | |
a6e3c44c |
89 | is $importcaller[0], 'ExplicitPackage', |
90 | 'import with hash has correct package'; |
91 | is $importcaller[1], 'explicit-file.pl', |
92 | 'import with hash has correct file'; |
93 | is $importcaller[2], 42, |
94 | 'import with hash has correct line'; |
7a9ec1de |
95 | is $versioncaller[0], 'ExplicitPackage', |
96 | 'VERSION with hash has correct package'; |
97 | is $versioncaller[1], 'explicit-file.pl', |
98 | 'VERSION with hash has correct file'; |
99 | is $versioncaller[2], 42, |
100 | 'VERSION with hash has correct line'; |
a6e3c44c |
101 | is $version, 219, |
102 | 'import with hash has correct version'; |
103 | |
104 | BEGIN { |
105 | package LevelExporter; |
106 | $INC{'LevelExporter.pm'} = __FILE__; |
107 | |
108 | sub import { |
109 | CheckFile->import::into({ |
110 | level => 1, |
111 | version => 219, |
112 | }); |
113 | } |
114 | } |
cc087979 |
115 | |
97e7f522 |
116 | @importcaller = (); |
7a9ec1de |
117 | @versioncaller = (); |
97e7f522 |
118 | $version = undef; |
119 | eval q{ |
120 | package ExplicitLevel; |
121 | |
122 | #line 42 "explicit-level.pl" |
123 | use LevelExporter; |
124 | 1; |
125 | } or die $@; |
126 | |
127 | is $importcaller[0], 'ExplicitLevel', |
128 | 'import with level in hash has correct package'; |
129 | is $importcaller[1], 'explicit-level.pl', |
130 | 'import with level in hash has correct file'; |
131 | is $importcaller[2], 42, |
132 | 'import with level in hash has correct line'; |
7a9ec1de |
133 | is $versioncaller[0], 'ExplicitLevel', |
134 | 'VERSION with level in hash has correct package'; |
135 | is $versioncaller[1], 'explicit-level.pl', |
136 | 'VERSION with level in hash has correct file'; |
137 | is $versioncaller[2], 42, |
138 | 'VERSION with level in hash has correct line'; |
97e7f522 |
139 | is $version, 219, |
140 | 'import with level in hash has correct version'; |
141 | |
cc087979 |
142 | ok( !IPC::Open3->can("open3"), "IPC::Open3 is unloaded" ); |
143 | IPC::Open3->import::into("TestPackage"); |
144 | ok( TestPackage->can("open3"), "IPC::Open3 was use'd and import::into'd" ); |