1 package Package::Subroutine 2 ; our $VERSION = '0.06' 3 4 ; sub export 5 { my $ns = (caller(1))[0] 6 ; shift() # rm package 7 # working shortcut for __PACKAGE__ 8 ; splice(@_,0,1,"".caller) if $_[0] eq '_' 9 ; _import_export($ns,@_) 10 } 11 12 ; sub import 13 { my $ns = (caller(0))[0] 14 ; shift() # rm package 15 ; _import_export($ns,@_) 16 } 17 18 ; sub _import_export 19 { my $namespace = shift 20 ; my $from = shift 21 ; my @methods = @_ 22 23 ; for ( @methods ) 24 { my $target = "${namespace}::${_}" 25 ; my $source = "${from}::${_}" 26 ; *$target = \&$source 27 } 28 } 29 30 ; sub version 31 { my ($f,$pkg,$num)=@_ 32 ; if( defined($num) ) 33 { $num=eval { UNIVERSAL::VERSION($pkg,$num) } 34 ; return $@ ? undef : $num 35 } 36 ; eval { UNIVERSAL::VERSION($pkg) } 37 } 38 39 ; sub install 40 { my ($pkg,$target,$name,$coderef)=@_ 41 ; $target="${target}::${name}" 42 ; *$target = $coderef 43 } 44 45 ; 1 46 47 __END__