5 If the first entry in an import list begins with /, ! or : then
6 treat the list as a series of specifications which either add to
7 or delete from the list of names to import. They are processed
8 left to right. Specifications are in the form:
10 [!]/pattern/ All names in @EXPORT and @EXPORT_OK which match
11 [!]name This name only
12 [!]:tag All names in $EXPORT_TAGS{":tag"}
13 [!]:DEFAULT All names in @EXPORT
17 @EXPORT = qw(A1 A2 A3 A4 A5);
18 @EXPORT_OK = qw(B1 B2 B3 B4 B5);
19 %EXPORT_TAGS = (':T1' => [qw(A1 A2 B1 B2)], ':T2' => [qw(A1 A2 B3 B4)]);
21 Note that you cannot use tags in @EXPORT or @EXPORT_OK.
22 Names in EXPORT_TAGS must also appear in @EXPORT or @EXPORT_OK.
26 use Module qw(:T2 !B3 A3);
27 use Socket qw(!/^[AP]F_/ !SOMAXCONN !SOL_SOCKET);
28 use POSIX qw(/^S_/ acos asin atan /^E/ !/^EXIT/);
41 # First make import warnings look like they're coming from the "use".
42 local $SIG{__WARN__} = sub {
44 $text =~ s/ at \S*Exporter.pm line \d+.\n//;
45 local $Carp::CarpLevel = 1; # ignore package calling us too.
53 *exports = \@{"${pkg}::EXPORT"};
56 *exports = \%{"${pkg}::EXPORT"};
58 grep(s/^&//, @exports);
59 @exports{@exports} = (1) x @exports;
60 foreach $extra (@{"${pkg}::EXPORT_OK"}) {
65 if ($imports[0] =~ m#^[/!:]#){
66 my(@allexports) = keys %exports;
67 my $tagsref = \%{"${pkg}::EXPORT_TAGS"};
70 # negated first item implies starting with default set:
71 unshift(@imports, ':DEFAULT') if $imports[0] =~ m/^!/;
74 my($mode,$spec) = m/^(!)?(.*)/;
75 $mode = '+' unless defined $mode;
77 @names = ($spec); # default, maybe overridden below
79 if ($spec =~ m:^/(.*)/$:){
81 @names = grep(/$patn/, @allexports); # XXX anchor by default?
83 elsif ($spec =~ m#^:(.*)# and $tagsref){
87 elsif ($tagsref and $tagdata = $tagsref->{$1}) {
92 warn "Import Mode $mode, Spec $spec, Names @names\n" if $Verbose;
94 map {delete $imports{$_}} @names; # delete @imports{@names} would be handy :-)
97 @imports{@names} = (1) x @names;
100 @imports = keys %imports;
103 foreach $sym (@imports) {
104 if (!$exports{$sym}) {
105 if ($sym !~ s/^&// || !$exports{$sym}) {
106 warn qq["$sym" is not exported by the $pkg module ],
107 "at $callfile line $callline\n";
113 die "Can't continue with import errors.\n" if $oops;
118 warn "Importing from $pkg into $callpkg: ",
119 join(", ",@imports),"\n" if ($Verbose && @imports);
120 foreach $sym (@imports) {
122 $type = $1 if $sym =~ s/^(\W)//;
123 *{"${callpkg}::$sym"} =
124 $type eq '&' ? \&{"${pkg}::$sym"} :
125 $type eq '$' ? \${"${pkg}::$sym"} :
126 $type eq '@' ? \@{"${pkg}::$sym"} :
127 $type eq '%' ? \%{"${pkg}::$sym"} :
128 $type eq '*' ? *{"${pkg}::$sym"} :
129 warn "Can't export symbol: $type$sym\n";
134 local ($callpkg, $callfile, $callline) = caller($ExportLevel);
136 export $pkg, $callpkg, @_;
141 *tags = \%{"${pkg}::EXPORT_TAGS"};
142 push(@{"${pkg}::EXPORT"},
143 map {$tags{$_} ? @{$tags{$_}} : $_} @_ ? @_ : keys %tags);