blib/lib/Sub/Talisman.pm

filter: Statementstmt 93.1% 95 / 102 Branchbran 44.4% 8 / 18 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 96.1% 25 / 26 Podpod 100% 4 / 4 totaltotal 86.9% 133 / 153 CC 13 SCAR 10.1
CC
13
Cov
85%
_identify
10.1
get_attribute_parameters
3.1
get_subs
3.0
CRAP 2.7
↑ Summary
1 package Sub::Talisman;
2  
3 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 $Sub::Talisman::AUTHORITY = 'cpan:TOBYINK';
9 1 $Sub::Talisman::VERSION = '0.006';
10 }
11  
12 1 ▶use Attribute::Handlers;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Scalar::Util qw( refaddr );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Sub::Util qw( subname set_subname );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 sub _identify
17 14 ▶{
Subroutine _identify: called CC=5 SCAR=23.1
18 14 my $sub = shift;
19 14 ▶ if (ref $sub)
Branch: 2 branches
BranchTrueFalseTotal
if (ref $sub) { } 14 0 14
elsif ($sub =~ /::/) { } 0 0 0
20 {
21 14 my ($p, $n) = subname($sub) =~ m/\A(.*)::([^:]+)\z/;
22 14 ▶ $n .= sprintf('(%d)', refaddr($sub)) if $n eq '__ANON__';
Branch: 1 branch
BranchTrueFalseTotal
if $n eq "__ANON__" 0 14 14
23 14 return ($p, $n);
24 }
25 elsif ($sub =~ /::/)
26 {
27 0 my ($p, $n) = ($sub =~ /^(.*)::(\w+)$/);
28 0 ▶ $p = 'main' if $p eq q();
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "" 0 0 0
29 0 return ($p, $n);
30 }
31 else
32 {
33 0 return ($_[0], $sub);
34 }
35 }
36  
37 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 my (%TALI, %FETCH);
39  
40 sub setup_for
41 4 ▶{
Subroutine setup_for: called CC=2 SCAR=6.9
Pod documented
42 4 my ($class, $caller, $opts) = @_;
43 4 my $atr = $opts->{attribute};
44 0 ▶ eval qq{
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine WWW: not called CC=1 SCAR=0.0
Subroutine XXX: called CC=1 SCAR=0.0
Subroutine YYY: called CC=1 SCAR=0.0
Subroutine ZZZ: called CC=1 SCAR=0.0
45 package $caller;
46 sub $atr :ATTR(CODE)
47 {
48 unshift \@_, q[$class], q[$caller];
49 my \$callback = "$class"->can("_callback");
50 goto \$callback;
51 }
52 };
53 namespace::clean->import(
54 -cleanee => $caller,
55 $opts->{attribute},
56 4 );
57 4 ▶ unless ($FETCH{$caller})
Branch: 1 branch
BranchTrueFalseTotal
unless ($FETCH{$caller}) 1 3 4
58 {
59 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
60 1 my $subname = "$caller\::FETCH_CODE_ATTRIBUTES";
61 1 ▶ *$subname = set_subname $subname => sub {
Subroutine FETCH_CODE_ATTRIBUTES: called CC=2 SCAR=7.1
62 1 my ($class, $sub) = @_;
63 1 ▶ return map { /(\w+)$/ ? $1 : () }
Branch: 1 branch
BranchTrueFalseTotal
/(\w+)$/ ? : 3 0 3
64 __PACKAGE__->get_attributes($sub);
65 1 };
66 1 $FETCH{$caller} = 1;
67 }
68 }
69  
70 sub import
71 1 ▶{
Subroutine import: called CC=2 SCAR=6.9
72 1 my $class = shift;
73 1 my $caller = caller;
74 1 foreach my $atr (@_)
75 {
76 4 $class->setup_for($caller, { attribute => $atr });
77 }
78 }
79  
80 sub _process_params
81 7 ▶{
Subroutine _process_params: called CC=1 SCAR=0.0
82 7 my ($class, $attr, $params) = @_;
83 7 return $params;
84 }
85  
86 sub _callback
87 7 ▶{
Subroutine _callback: called CC=1 SCAR=0.0
88 7 my ($class, $installation_pkg, $caller_pkg, $glob, $ref, $attr, $params, $step, $file, $line) = @_;
89 7 my ($p, $n) = _identify($ref, scalar caller);
90 7 my $full_attr = join q[::], $installation_pkg, $attr;
91 7 my $obj = $class->_process_params($full_attr, $params);
92 7 $TALI{$p}{$n}{$full_attr} = $obj;
93 }
94  
95 sub get_attributes
96 4 ▶{
Subroutine get_attributes: called CC=2 SCAR=7.0
Pod documented
97 4 my ($class, $sub) = @_;
98 4 my ($p, $n) = _identify($sub, scalar caller);
99 4 ▶ my %hash = %{ $TALI{$p}{$n} || {} };
Condition50%1/2
$TALI{$p}{$n} || {}
l!l
40
MC/DC0%0/1
$TALI{$p}{$n} || {}
$TALI{$p}{$n}
Truth table50%1/2
A
A= $TALI{$p}{$n}
Aresult
11
00
100 4 return sort keys %hash;
101 }
102  
103 sub get_attribute_parameters
104 3 ▶{
Subroutine get_attribute_parameters: called CC=3 SCAR=11.3
Pod documented
105 3 my ($class, $sub, $attr) = @_;
106 3 ▶ $attr = scalar(caller).'::'.$attr unless $attr =~ /::/;
Branch: 1 branch
BranchTrueFalseTotal
unless $attr =~ /::/ 0 3 3
107 3 my ($p, $n) = _identify($sub, scalar caller);
108 3 ▶ return unless exists $TALI{$p}{$n}{$attr};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $TALI{$p}{$n}{$attr} 0 3 3
109 3 return $TALI{$p}{$n}{$attr};
110 }
111  
112 sub get_subs
113 3 ▶{
Subroutine get_subs: called CC=3 SCAR=11.0
Pod documented
114 3 my ($class, $attr) = @_;
115 3 ▶ $attr = scalar(caller).'::'.$attr unless $attr =~ /::/;
Branch: 1 branch
BranchTrueFalseTotal
unless $attr =~ /::/ 0 3 3
116 3 my @subs;
117 3 foreach my $pkg (keys %TALI)
118 {
119 push @subs,
120 7 map { "$pkg\::$_" }
121 9 grep { exists $TALI{$pkg}{$_}{$attr} }
122 9 grep { not /^__ANON__\([0-9]+\)$/ }
123 3 keys %{ $TALI{$pkg} };
124 }
125 3 return @subs;
126 }
127  
128 1 1;
129  
130 __END__
↑ Summary