summaryrefslogtreecommitdiff
path: root/lib/Exporter.pm
blob: 0b021b3d712bb77ae721c9ed52a5fa3dd9da4348 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package Exporter;

require 5.000;

sub import {
    my ($callpack, $callfile, $callline) = caller($ExportLevel);
    my $pack = shift;
    my @imports = @_;
    *exports = \@{"${pack}::EXPORT"};
    if (@imports) {
	my $oops;
	my $type;
	*exports = \%{"${pack}::EXPORT"};
	if (!%exports) {
	    grep(s/^&//, @exports);
	    @exports{@exports} = (1) x  @exports;
	}
	foreach $sym (@imports) {
	    if (!$exports{$sym}) {
		if ($sym !~ s/^&// || !$exports{$sym}) {
		    warn "$sym is not exported by the $pack module ",
			    "at $callfile line $callline\n";
		    $oops++;
		    next;
		}
	    }
	}
	die "Can't continue with import errors.\n" if $oops;
    }
    else {
	@imports = @exports;
    }
    foreach $sym (@imports) {
	$type = '&';
	$type = $1 if $sym =~ s/^(\W)//;
	*{"${callpack}::$sym"} =
	    $type eq '&' ? \&{"${pack}::$sym"} :
	    $type eq '$' ? \${"${pack}::$sym"} :
	    $type eq '@' ? \@{"${pack}::$sym"} :
	    $type eq '%' ? \%{"${pack}::$sym"} :
	    $type eq '*' ?  *{"${pack}::$sym"} :
		    warn "Can't export symbol: $type$sym\n";
    }
};

1;