my %pkgs;
+sub _validate_pkg {
+ my ($pkg, $cur) = @_;
+ return $cur unless $pkg;
+ croak 'Invalid package name' if ref $pkg
+ or $pkg =~ /(?:-|[^\w:])/
+ or $pkg =~ /(?:\A\d|\b:(?::\d|(?:::+)?\b))/;
+ $pkg =~ s/::$//;
+ $pkg = $cur . $pkg if $pkg eq '' or $pkg =~ /^::/;
+ $pkg;
+}
+
sub import {
shift;
croak 'Optional arguments must be passed as keys/values pairs' if @_ % 2;
my %args = @_;
- my $cur = (caller 1)[0];
- my $pkg;
- if ($pkg = $args{in}) {
- croak 'Invalid package name' if ref $pkg
- or $pkg =~ /(?:-|[^\w:])/
- or $pkg =~ /(?:\A\d|\b:(?::\d|(?:::+)?\b))/;
- $pkg =~ s/::$//;
- $pkg = $cur . $pkg if $pkg eq '' or $pkg =~ /^::/;
- } else {
- $pkg = $cur;
- }
+ my $cur = (caller 1)[0];
+ my $in = _validate_pkg $args{in}, $cur;
$^H{bareword} = 1;
- ++$pkgs{$pkg};
+ ++$pkgs{$in};
no strict 'refs';
- cast %{$pkg . '::'}, $wiz, $pkg;
+ cast %{$in . '::'}, $wiz, $in;
}
sub unimport {