Commit | Line | Data |
2afb5246 |
1 | use strict; |
2 | use warnings FATAL => 'all'; |
1615d435 |
3 | use Test::More qw(no_plan); |
2afb5246 |
4 | |
5 | BEGIN { |
6 | |
7 | package MyExporter; |
8 | |
9 | use base qw(Exporter); |
10 | |
11 | our @EXPORT_OK = qw(thing); |
12 | |
13 | sub thing { 'thing' } |
14 | |
cc087979 |
15 | $INC{"MyExporter.pm"} = 1; |
16 | |
2afb5246 |
17 | package MultiExporter; |
18 | |
19 | use Import::Into; |
20 | |
21 | sub import { |
22 | my $target = caller; |
23 | warnings->import::into($target); |
24 | MyExporter->import::into($target, 'thing'); |
e5f9555d |
25 | CheckFile->import::into(1); |
568eef3e |
26 | |
2afb5246 |
27 | } |
28 | |
29 | $INC{"MultiExporter.pm"} = 1; |
30 | } |
31 | |
e5f9555d |
32 | my @checkcaller; |
568eef3e |
33 | my $checkversion; |
e5f9555d |
34 | BEGIN { |
35 | |
36 | package CheckFile; |
37 | |
38 | sub import { |
39 | @checkcaller = caller; |
40 | } |
568eef3e |
41 | sub VERSION { |
42 | $checkversion = $_[1]; |
43 | } |
e5f9555d |
44 | |
45 | $INC{"CheckFile.pm"} = 1; |
46 | } |
47 | |
8afc1658 |
48 | eval q{ |
2afb5246 |
49 | |
50 | package TestPackage; |
51 | |
b95fe8b9 |
52 | no warnings FATAL => 'all'; |
2afb5246 |
53 | |
8afc1658 |
54 | #line 1 "import_into_inline.pl" |
2afb5246 |
55 | use MultiExporter; |
56 | |
57 | sub test { |
58 | thing . undef |
59 | } |
8afc1658 |
60 | 1; |
61 | } or die $@; |
2afb5246 |
62 | |
63 | my @w; |
64 | |
65 | is(do { |
66 | local $SIG{__WARN__} = sub { push @w, @_; }; |
8afc1658 |
67 | TestPackage::test(); |
2afb5246 |
68 | }, 'thing', 'returned thing ok'); |
69 | |
70 | is(scalar @w, 1, 'Only one entry in @w'); |
71 | |
72 | like($w[0], qr/uninitialized/, 'Correct warning'); |
e5f9555d |
73 | |
74 | is $checkcaller[0], 'TestPackage', 'import by level has correct package'; |
8afc1658 |
75 | is $checkcaller[1], 'import_into_inline.pl', 'import by level has correct file'; |
e5f9555d |
76 | is $checkcaller[2], 1, 'import by level has correct line'; |
568eef3e |
77 | |
78 | CheckFile->import::into({ |
79 | package => 'ExplicitPackage', |
80 | filename => 'explicit-file.pl', |
81 | line => 42, |
82 | version => 219, |
83 | }); |
84 | |
85 | is $checkcaller[0], 'ExplicitPackage', 'import with hash has correct package'; |
86 | is $checkcaller[1], 'explicit-file.pl', 'import with hash has correct file'; |
87 | is $checkcaller[2], 42, 'import with hash has correct line'; |
88 | is $checkversion, 219, 'import with hash has correct version'; |
cc087979 |
89 | |
90 | ok( !IPC::Open3->can("open3"), "IPC::Open3 is unloaded" ); |
91 | IPC::Open3->import::into("TestPackage"); |
92 | ok( TestPackage->can("open3"), "IPC::Open3 was use'd and import::into'd" ); |