| 1 | package Package::Subroutine; | ||||||||||
| 2 | # ************************** | ||||||||||
| 3 | 6 | $VERSION = '0.22.001'; | |||||||||
| 4 | # **************** | ||||||||||
| 5 | 6 | ; no strict 'refs' | |||||||||
| 6 | |||||||||||
| 7 | 6 | ▶ | ; use Class::ISA () | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 6 | ▶ | ; sub export_to_caller | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | { my ($self,$level) = @_ | ||||||||
|
Subroutine
export_to_caller: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 11 | 1 | ; my $namespace = (caller($level))[0] | |||||||||
| 12 | ; return sub | ||||||||||
| 13 | 1 | ▶ | { my ($from,@methods) = @_ | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||
| 14 | 1 | ▶ | ; $from = caller if $from eq '_' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | 1 | ; exporter($namespace,$from,@methods) | |||||||||
| 16 | } | ||||||||||
| 17 | 1 | } | |||||||||
| 18 | |||||||||||
| 19 | ; sub export_to | ||||||||||
| 20 | 0 | ▶ | { my ($self,$namespace) = @_ | ||||||||
|
Subroutine
export_to: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 21 | ; return sub | ||||||||||
| 22 | 0 | ▶ | { my ($from,@methods) = @_ | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 23 | 0 | ▶ | ; $from = caller if $from eq '_' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 0 | ; exporter($namespace,$from,@methods) | |||||||||
| 25 | } | ||||||||||
| 26 | 0 | } | |||||||||
| 27 | |||||||||||
| 28 | ; sub export | ||||||||||
| 29 | 0 | ▶ | { my $ns = (caller(1))[0] | ||||||||
|
Subroutine
export: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 30 | ; shift() # rm package | ||||||||||
| 31 | # working shortcut for __PACKAGE__ | ||||||||||
| 32 | 0 | ▶ | ; splice(@_,0,1,"".caller) if $_[0] eq '_' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 0 | ; exporter($ns,@_) | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | ; sub import | ||||||||||
| 37 | 7 | ▶ | { my $ns = (caller(0))[0] | ||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||
| 38 | ; shift() # rm package | ||||||||||
| 39 | 7 | ; exporter($ns,@_) | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | ; sub mixin | ||||||||||
| 43 | 1 | ▶ | { my $ns = (caller(0))[0] | ||||||||
|
Subroutine
mixin: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 44 | 1 | ; my $pkg = shift() | |||||||||
| 45 | 1 | ▶ | ; if(@_==1) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 1 | { push @_, $pkg->findsubs($_[0]) | |||||||||
| 47 | } | ||||||||||
| 48 | 1 | ; exporter($ns,@_) | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | ; sub exporter | ||||||||||
| 52 | 9 | ▶ | { my $namespace = shift | ||||||||
|
Subroutine
exporter: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 53 | 9 | ; my $from = shift | |||||||||
| 54 | 9 | ; my @methods = @_ | |||||||||
| 55 | 9 | ; local $_ | |||||||||
| 56 | |||||||||||
| 57 | 9 | ; for ( @methods ) | |||||||||
| 58 | 25 | { my $srcm = my $trgm = $_ | |||||||||
| 59 | 25 | ▶ | ; ($srcm,$trgm) = @$_ if ref eq 'ARRAY' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 25 | ; my $target = "${namespace}::${trgm}" | |||||||||
| 61 | 25 | ; my $source = "${from}::${srcm}" | |||||||||
| 62 | 25 | ; *$target = \&$source | |||||||||
| 63 | } | ||||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | ; sub version | ||||||||||
| 67 | 0 | ▶ | { my ($f,$pkg,$num)=@_ | ||||||||
|
Subroutine
version: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 68 | 0 | ▶ | ; if( defined($num) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 0 | { $num=eval { UNIVERSAL::VERSION($pkg,$num) } | |||||||||
| 70 | 0 | ▶ | ; return $@ ? undef : $num | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | } | ||||||||||
| 72 | 0 | ; eval { UNIVERSAL::VERSION($pkg) } | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | ; sub install | ||||||||||
| 76 | 0 | ▶ | { my ($pkg,$target,$name,$coderef)=@_ | ||||||||
|
Subroutine
install: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 77 | 0 | ; $target="${target}::${name}" | |||||||||
| 78 | 0 | ; *$target = $coderef | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | ; sub isdefined | ||||||||||
| 82 | 2 | ▶ | { my ($pkg,$namespace,$subname)=@_ | ||||||||
|
Subroutine
isdefined: called CC=3 SCAR=12.3
Pod
documented
| |||||||||||
| 83 | 2 | ▶ | ; unless($subname) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 0 | { my @ns = split /\'|\:\:/, $namespace | |||||||||
| 85 | 0 | ; $subname = pop @ns | |||||||||
| 86 | 0 | ; $namespace = join "::",@ns | |||||||||
| 87 | } | ||||||||||
| 88 | 2 | ; *{"${namespace}::${subname}"}{CODE} || undef | |||||||||
| 89 | 2 | ▶ | } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | |||||||||||
| 91 | ; sub findsubs | ||||||||||
| 92 | 7 | ▶ | { my ($self,$class)=@_ | ||||||||
|
Subroutine
findsubs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 93 | 7 | ; grep { *{"${class}::${_}"}{CODE} } keys %{"${class}::"} | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | ; sub findmethods | ||||||||||
| 97 | 2 | ▶ | { my ($self,$class)=@_ | ||||||||
|
Subroutine
findmethods: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 98 | 34 | ; my %methods = map { $_ => 1 } | |||||||||
| 99 | 2 | map { $self->findsubs($_) } | |||||||||
| 100 | reverse (Class::ISA::self_and_super_path($class),'UNIVERSAL') | ||||||||||
| 101 | 2 | ; return keys %methods | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 6 | ; 1 | |||||||||
| 105 | |||||||||||
| 106 | __END__ | ||||||||||