Class/Method/ModifiersX/Augment.pm

filter: Statementstmt 96.6% 57 / 59 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 100% 2 / 2 totaltotal 93.9% 77 / 82 CC 7 SCAR 8.4
CC
7
Cov
93%
_mk_around
5.2
augment
2.0
inner
2.0
CRAP 2.3
« MooX/Augment.pm ↑ Summary
1 package Class::Method::ModifiersX::Augment;
2  
3 2 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 $Class::Method::ModifiersX::Augment::AUTHORITY = 'cpan:TOBYINK';
9 2 $Class::Method::ModifiersX::Augment::VERSION = '0.002';
10 }
11  
12 2 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 our %EXPORT_TAGS = (
14 all => [our @EXPORT_OK = our @EXPORT = qw( augment inner )],
15 );
16  
17 2 ▶use Class::Method::Modifiers qw( install_modifier );
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 2 ▶use if ($] >= 5.010), 'mro';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use if ($] < 5.010), 'MRO::Compat';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 2 our %INNER_BODY = ();
23 2 our %INNER_ARGS = ();
24  
25 sub _mk_around
26 2 ▶{
Subroutine _mk_around: called CC=5 SCAR=16.4
27 2 my ($into, $code, $name) = @_;
28 2 ▶ unless ($name)
Branch: 1 branch
BranchTrueFalseTotal
unless ($name) 0 2 2
29 {
30 0 require Carp;
31 0 Carp::croak("need name");
32 }
33
34 2 my $super;
35 2 my @isa = @{ mro::get_linear_isa($into) };
36 2 shift @isa;
37 2 SUPER: foreach my $pkg (@isa)
38 {
39 2 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
40 2 ▶ if (exists &{"${pkg}::${name}"})
Branch: 1 branch
BranchTrueFalseTotal
if (exists &{"${pkg}::$name";}) 2 0 2
41 {
42 2 ▶ $super = $pkg and last SUPER;
Branch: 1 branch
BranchTrueFalseTotal
$super = $pkg and last SUPER 2 0 2
43 }
44 }
45
46 3 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
47 3 my $super_body = shift;
48 3 local $INNER_ARGS{$super} = [ @_ ];
49 3 local $INNER_BODY{$super} = $code;
50 3 return $super_body->(@_);
51 2 };
52 }
53  
54 sub augment
55 2 ▶{
Subroutine augment: called CC=2 SCAR=6.9
Pod documented
56 2 my $into = caller(0);
57 2 my $code = pop;
58
59 2 foreach my $name (@_)
60 {
61 2 my $sub = _mk_around($into, $code, $name);
62 2 install_modifier($into, 'around', $name, $sub);
63 }
64 }
65  
66 sub inner ()
67 5 ▶{
Subroutine inner: called CC=2 SCAR=6.9
Pod documented
68 5 my $pkg = caller;
69
70 5 ▶ if (my $body = $INNER_BODY{$pkg}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $body = $Class::Method::ModifiersX::Augment::INNER_BODY{$pkg}) 3 2 5
71 3 my @args = @{ $INNER_ARGS{$pkg} };
72 3 local $INNER_ARGS{$pkg};
73 3 local $INNER_BODY{$pkg};
74 3 return $body->(@args);
75 }
76
77 2 return;
78 }
79  
80  
81  
82 2 1;
83  
84 __END__
« MooX/Augment.pm ↑ Summary