This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 5.0 alpha 6
[perl5.git] / lib / Exporter.pm
CommitLineData
8990e307
LW
1package Exporter;
2
3require 5.000;
4
5sub import {
6 my ($callpack, $callfile, $callline) = caller($ExportLevel);
7 my $pack = shift;
8 my @imports = @_;
9 *exports = \@{"${pack}::EXPORT"};
10 if (@imports) {
11 my $oops;
12 my $type;
13 *exports = \%{"${pack}::EXPORT"};
14 if (!%exports) {
15 grep(s/^&//, @exports);
16 @exports{@exports} = (1) x @exports;
17 }
18 foreach $sym (@imports) {
19 if (!$exports{$sym}) {
20 if ($sym !~ s/^&// || !$exports{$sym}) {
21 warn "$sym is not exported by the $pack module ",
22 "at $callfile line $callline\n";
23 $oops++;
24 next;
25 }
26 }
27 }
28 die "Can't continue with import errors.\n" if $oops;
29 }
30 else {
31 @imports = @exports;
32 }
33 foreach $sym (@imports) {
34 $type = '&';
35 $type = $1 if $sym =~ s/^(\W)//;
36 *{"${callpack}::$sym"} =
37 $type eq '&' ? \&{"${pack}::$sym"} :
38 $type eq '$' ? \${"${pack}::$sym"} :
39 $type eq '@' ? \@{"${pack}::$sym"} :
40 $type eq '%' ? \%{"${pack}::$sym"} :
41 $type eq '*' ? *{"${pack}::$sym"} :
42 warn "Can't export symbol: $type$sym\n";
43 }
44};
45
461;