allow specifying import options as hash, including version check
[p5sagit/Import-Into.git] / t / import_into.t
CommitLineData
2afb5246 1use strict;
2use warnings FATAL => 'all';
1615d435 3use Test::More qw(no_plan);
2afb5246 4
5BEGIN {
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 30my @checkcaller;
568eef3e 31my $checkversion;
e5f9555d 32BEGIN {
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 46BEGIN {
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
60my @w;
61
62is(do {
63 local $SIG{__WARN__} = sub { push @w, @_; };
64 TestPackage::test;
65}, 'thing', 'returned thing ok');
66
67is(scalar @w, 1, 'Only one entry in @w');
68
69like($w[0], qr/uninitialized/, 'Correct warning');
e5f9555d 70
71is $checkcaller[0], 'TestPackage', 'import by level has correct package';
72is $checkcaller[1], __FILE__, 'import by level has correct file';
73is $checkcaller[2], 1, 'import by level has correct line';
568eef3e 74
75CheckFile->import::into({
76 package => 'ExplicitPackage',
77 filename => 'explicit-file.pl',
78 line => 42,
79 version => 219,
80});
81
82is $checkcaller[0], 'ExplicitPackage', 'import with hash has correct package';
83is $checkcaller[1], 'explicit-file.pl', 'import with hash has correct file';
84is $checkcaller[2], 42, 'import with hash has correct line';
85is $checkversion, 219, 'import with hash has correct version';