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 | |
15 | package MultiExporter; |
16 | |
17 | use Import::Into; |
18 | |
19 | sub import { |
20 | my $target = caller; |
21 | warnings->import::into($target); |
22 | MyExporter->import::into($target, 'thing'); |
e5f9555d |
23 | CheckFile->import::into(1); |
568eef3e |
24 | |
2afb5246 |
25 | } |
26 | |
27 | $INC{"MultiExporter.pm"} = 1; |
28 | } |
29 | |
e5f9555d |
30 | my @checkcaller; |
568eef3e |
31 | my $checkversion; |
e5f9555d |
32 | BEGIN { |
33 | |
34 | package CheckFile; |
35 | |
36 | sub import { |
37 | @checkcaller = caller; |
38 | } |
568eef3e |
39 | sub VERSION { |
40 | $checkversion = $_[1]; |
41 | } |
e5f9555d |
42 | |
43 | $INC{"CheckFile.pm"} = 1; |
44 | } |
45 | |
8afc1658 |
46 | eval q{ |
2afb5246 |
47 | |
48 | package TestPackage; |
49 | |
50 | no warnings; |
51 | |
8afc1658 |
52 | #line 1 "import_into_inline.pl" |
2afb5246 |
53 | use MultiExporter; |
54 | |
55 | sub test { |
56 | thing . undef |
57 | } |
8afc1658 |
58 | 1; |
59 | } or die $@; |
2afb5246 |
60 | |
61 | my @w; |
62 | |
63 | is(do { |
64 | local $SIG{__WARN__} = sub { push @w, @_; }; |
8afc1658 |
65 | TestPackage::test(); |
2afb5246 |
66 | }, 'thing', 'returned thing ok'); |
67 | |
68 | is(scalar @w, 1, 'Only one entry in @w'); |
69 | |
70 | like($w[0], qr/uninitialized/, 'Correct warning'); |
e5f9555d |
71 | |
72 | is $checkcaller[0], 'TestPackage', 'import by level has correct package'; |
8afc1658 |
73 | is $checkcaller[1], 'import_into_inline.pl', 'import by level has correct file'; |
e5f9555d |
74 | is $checkcaller[2], 1, 'import by level has correct line'; |
568eef3e |
75 | |
76 | CheckFile->import::into({ |
77 | package => 'ExplicitPackage', |
78 | filename => 'explicit-file.pl', |
79 | line => 42, |
80 | version => 219, |
81 | }); |
82 | |
83 | is $checkcaller[0], 'ExplicitPackage', 'import with hash has correct package'; |
84 | is $checkcaller[1], 'explicit-file.pl', 'import with hash has correct file'; |
85 | is $checkcaller[2], 42, 'import with hash has correct line'; |
86 | is $checkversion, 219, 'import with hash has correct version'; |