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 | |
2afb5246 |
46 | BEGIN { |
47 | |
48 | package TestPackage; |
49 | |
50 | no warnings; |
51 | |
e5f9555d |
52 | #line 1 |
2afb5246 |
53 | use MultiExporter; |
54 | |
55 | sub test { |
56 | thing . undef |
57 | } |
58 | } |
59 | |
60 | my @w; |
61 | |
62 | is(do { |
63 | local $SIG{__WARN__} = sub { push @w, @_; }; |
64 | TestPackage::test; |
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 | |
71 | is $checkcaller[0], 'TestPackage', 'import by level has correct package'; |
72 | is $checkcaller[1], __FILE__, 'import by level has correct file'; |
73 | is $checkcaller[2], 1, 'import by level has correct line'; |
568eef3e |
74 | |
75 | CheckFile->import::into({ |
76 | package => 'ExplicitPackage', |
77 | filename => 'explicit-file.pl', |
78 | line => 42, |
79 | version => 219, |
80 | }); |
81 | |
82 | is $checkcaller[0], 'ExplicitPackage', 'import with hash has correct package'; |
83 | is $checkcaller[1], 'explicit-file.pl', 'import with hash has correct file'; |
84 | is $checkcaller[2], 42, 'import with hash has correct line'; |
85 | is $checkversion, 219, 'import with hash has correct version'; |