be compatible with perl 5.6
[p5sagit/Import-Into.git] / t / import_into.t
1 use strict;
2 use warnings FATAL => 'all';
3 use Test::More qw(no_plan);
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');
23     CheckFile->import::into(1);
24
25   }
26
27   $INC{"MultiExporter.pm"} = 1;
28 }
29
30 my @checkcaller;
31 my $checkversion;
32 BEGIN {
33
34   package CheckFile;
35
36   sub import {
37     @checkcaller = caller;
38   }
39   sub VERSION {
40     $checkversion = $_[1];
41   }
42
43   $INC{"CheckFile.pm"} = 1;
44 }
45
46 eval q{
47
48   package TestPackage;
49
50   no warnings FATAL => 'all';
51
52 #line 1 "import_into_inline.pl"
53   use MultiExporter;
54
55   sub test {
56     thing . undef
57   }
58   1;
59 } or die $@;
60
61 my @w;
62
63 is(do {
64   local $SIG{__WARN__} = sub { push @w, @_; };
65   TestPackage::test();
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');
71
72 is $checkcaller[0], 'TestPackage', 'import by level has correct package';
73 is $checkcaller[1], 'import_into_inline.pl', 'import by level has correct file';
74 is $checkcaller[2], 1, 'import by level has correct line';
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';