|
Packit |
1c5632 |
use Sub::Install;
|
|
Packit |
1c5632 |
use Test::More tests => 4;
|
|
Packit |
1c5632 |
|
|
Packit |
1c5632 |
use strict;
|
|
Packit |
1c5632 |
use warnings;
|
|
Packit |
1c5632 |
|
|
Packit |
1c5632 |
BEGIN { use_ok('Sub::Install'); }
|
|
Packit |
1c5632 |
|
|
Packit |
1c5632 |
package Bar;
|
|
Packit |
1c5632 |
{ no warnings 'once';
|
|
Packit |
1c5632 |
*import = Sub::Install::exporter { exports => [ qw(foo) ] };
|
|
Packit |
1c5632 |
}
|
|
Packit |
1c5632 |
sub foo { return 10; }
|
|
Packit |
1c5632 |
|
|
Packit |
1c5632 |
package main;
|
|
Packit |
1c5632 |
|
|
Packit |
1c5632 |
eval { Bar->import('bar'); };
|
|
Packit |
1c5632 |
like($@, qr/'bar' is not exported/, "exception on bad import");
|
|
Packit |
1c5632 |
|
|
Packit |
1c5632 |
eval { foo(); };
|
|
Packit |
1c5632 |
like($@, qr/Undefined subroutine/, "foo isn't imported yet");
|
|
Packit |
1c5632 |
|
|
Packit |
1c5632 |
Bar->import(qw(foo));
|
|
Packit |
1c5632 |
is(foo(), 10, "foo imported from Bar OK");
|