sub import { # Determine the package name of the caller. my $callpack = caller; # Grab the list of symbols that need to be exported. my (undef, @imports) = @_; my ($sym, $ch); foreach (@imports) { # For each "var", find the sigil and the symbol. if (($ch, $sym) = /^([\$\@\%\*\&])(.+)/) { # If the symbol contains non-word characters... if ($sym =~ /\W/) { # time for a more-detailed check-up if ($sym =~ /^\w+[[{].*[]}]$/) { # We're being asked to declare an array or hash element. That's not cool. require Carp; Carp::croak("Can't declare individual elements of hash or array"); } elsif (warnings::enabled() and length($sym) == 1 and $sym !~ tr/a-zA-Z//) { # If it's a special punctuation variable... warnings::warn("No need to declare built-in vars"); } elsif (($^H &= strict::bits('vars'))) { # If we're strict, disallow funky variable names. require Carp; Carp::croak("'$_' is not a valid variable name under strict vars"); } } # Build up the fully-qualified symbol name. $sym = "${callpack}::$sym" unless $sym =~ /::/; # Vivify the symbol name within the appropriate package/namespace. *$sym = ( $ch eq "\$" ? \$$sym : $ch eq "\@" ? \@$sym : $ch eq "\%" ? \%$sym : $ch eq "\*" ? \*$sym : $ch eq "\&" ? \&$sym : do { require Carp; Carp::croak("'$_' is not a valid variable name"); }); } else { # This is odd... we weren't given a sigil. require Carp; Carp::croak("'$_' is not a valid variable name"); } } };