File Coverage

blib/lib/Package/Subroutine.pm
Criterion Covered Total %
statement 50 72 69.4
branch 6 18 33.3
condition n/a
subroutine 12 17 70.5
pod 10 10 100.0
total 78 117 66.6


line stmt bran cond sub pod time code
1             package Package::Subroutine;
2             # **************************
3 6     6   915325 use strict; use warnings;
  6     6   11  
  6         238  
  6         30  
  6         10  
  6         492  
4             our $VERSION = 'v0.23.1';
5             # ***********************
6 6         198 ; no strict 'refs'
7              
8 6     6   36 ; use Class::ISA ()
  6         17  
9              
10 6     6   3815 ; sub export_to_caller
  6         12409  
  6         6304  
11 1     1 1 253425 { my ($self,$level) = @_
12 1         7 ; my $namespace = (caller($level))[0]
13             ; return sub
14 1     1   5 { my ($from,@methods) = @_
15 1 50       5 ; $from = caller if $from eq '_'
16 1         6 ; exporter($namespace,$from,@methods)
17             }
18 1         10 }
19              
20             ; sub export_to
21 0     0 1 0 { my ($self,$namespace) = @_
22             ; return sub
23 0     0   0 { my ($from,@methods) = @_
24 0 0       0 ; $from = caller if $from eq '_'
25 0         0 ; exporter($namespace,$from,@methods)
26             }
27 0         0 }
28              
29             ; sub export
30 0     0 1 0 { my $ns = (caller(1))[0]
31             ; shift() # rm package
32             # working shortcut for __PACKAGE__
33 0 0       0 ; splice(@_,0,1,"".caller) if $_[0] eq '_'
  0         0  
34 0         0 ; exporter($ns,@_)
35             }
36              
37             ; sub import
38 9     9   173341 { my $ns = (caller(0))[0]
39             ; shift() # rm package
40 9         25 ; exporter($ns,@_)
  9         30  
41             }
42              
43             ; sub mixin
44 1     1 1 204495 { my $ns = (caller(0))[0]
45 1         3 ; my $pkg = shift()
46 1 50       11 ; if(@_==1)
47 1         6 { push @_, $pkg->findsubs($_[0])
48             }
49 1         7 ; exporter($ns,@_)
50             }
51              
52             ; sub exporter
53 11     11 1 40 { my $namespace = shift
54 11         23 ; my $from = shift
55 11         41 ; my @methods = @_
56 11         23 ; local $_
57              
58 11         4531 ; for ( @methods )
59 26         48 { my $srcm = my $trgm = $_
60 26 50       99 ; ($srcm,$trgm) = @$_ if ref eq 'ARRAY'
61 26         49 ; my $target = "${namespace}::${trgm}"
62 26         47 ; my $source = "${from}::${srcm}"
63 26         2214 ; *$target = \&$source
64             }
65             }
66              
67             ; sub version
68 0     0 1 0 { my ($f,$pkg,$num)=@_
69 0 0       0 ; if( defined($num) )
70 0         0 { $num=eval { UNIVERSAL::VERSION($pkg,$num) }
  0         0  
71 0 0       0 ; return $@ ? undef : $num
72             }
73 0         0 ; eval { UNIVERSAL::VERSION($pkg) }
  0         0  
74             }
75              
76             ; sub install
77 0     0 1 0 { my ($pkg,$target,$name,$coderef)=@_
78 0         0 ; $target="${target}::${name}"
79 0         0 ; *$target = $coderef
80             }
81              
82             ; sub isdefined
83 2     2 1 174516 { my ($pkg,$namespace,$subname)=@_
84 2 50       9 ; unless($subname)
85 0         0 { my @ns = split /\'|\:\:/, $namespace
86 0         0 ; $subname = pop @ns
87 0         0 ; $namespace = join "::",@ns
88             }
89 2         21 ; *{"${namespace}::${subname}"}{CODE} || undef
90 2 100       4 }
91              
92             ; sub findsubs
93 10     10 1 259257 { my ($self,$class)=@_
94 10         16 ; grep { *{"${class}::${_}"}{CODE} } keys %{"${class}::"}
  93         143  
  93         304  
  10         68  
95             }
96              
97             ; sub findmethods
98 3     3 1 7185 { my ($self,$class)=@_
99 51         122 ; my %methods = map { $_ => 1 }
100 3         15 map { $self->findsubs($_) }
  8         159  
101             reverse (Class::ISA::self_and_super_path($class),'UNIVERSAL')
102 3         54 ; return keys %methods
103             }
104              
105             ; 1
106              
107             __END__