Agent/LexWrap.pm

filter: Statementstmt 48.8% 42 / 86 Branchbran 13.0% 6 / 46 Conditioncond 16.6% 4 / 24 MC/DCmcdc 16.6% 2 / 12 Subroutinesub 55.0% 11 / 20 Podpod 100% 1 / 1 totaltotal 34.9% 66 / 189 CC 34 SCAR 46.6
CC
34
Cov
33%
__ANON__
272.0
wrap
102.7
__ANON__
10.6
CRAP 105.7
« Agent/Frameworks/Mojolicious.pm ↑ Summary Agent.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package PerlGuard::Agent::LexWrap;
4 # ABSTRACT: Lexically scoped subroutine wrappers
5  
6 1 our $VERSION = '0.26';
7  
8 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 {
11 1 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 16 ▶*CORE::GLOBAL::caller = sub (;$) {
Subroutine __ANON__: called CC=9 SCAR=23.6
13 16 ▶ my ($height) = ($_[0]||0);
Condition100%2/2
$_[0] || 0
l!l
124
MC/DC100%1/1
$_[0] || 0
$_[0]
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
14 16 my $i=1;
15 16 my $name_cache;
16 16 while (1) {
17 40 ▶ my @caller = CORE::caller($i++) or return;
Branch: 1 branch
BranchTrueFalseTotal
my(@caller) = caller $i++ or return 40 0 40
18 40 ▶ $caller[3] = $name_cache if $name_cache;
Branch: 1 branch
BranchTrueFalseTotal
if $name_cache 0 40 40
19 40 ▶ $name_cache = $caller[0] eq 'PerlGuard::Agent::LexWrap' ? $caller[3] : '';
Branch: 1 branch
BranchTrueFalseTotal
$caller[0] eq 'PerlGuard::Agent::LexWrap' ? : 0 40 40
20 40 ▶ next if $name_cache || $height-- != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $name_cache or $height-- != 0 24 16 40
Condition66%2/3
$name_cache or $height-- != 0
l!l&&r!l&&!r
02416
MC/DC50%1/2
$name_cache or $height-- != 0
$name_cache $height-- != 0
Truth table66%2/3
A or B
A= $name_cacheB= $height-- != 0
ABresult
1X1
011
000
21 16 ▶ return wantarray ? @_ ? @caller : @caller[0..2] : $caller[0];
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 0 16 16
@_ ? : 0 0 0
22 }
23 1 };
24 }
25  
26 1 ▶sub import { no strict 'refs'; *{caller()."::wrap"} = \&wrap }
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine import: called CC=1 SCAR=0.0
27  
28 0 ▶sub wrap (*@) { ## no critic Prototypes
Subroutine wrap: not called CC=11 SCAR=46.3
Pod documented
29 0 my ($typeglob, %wrapper) = @_;
30 0 ▶ $typeglob = (ref $typeglob || $typeglob =~ /::/)
Branch: 1 branch
BranchTrueFalseTotal
ref $typeglob || $typeglob =~ /::/ ? : 0 0 0
Condition0%0/3
ref $typeglob or $typeglob =~ /::/
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $typeglob or $typeglob =~ /::/
ref $typeglob $typeglob =~ /::/
Truth table0%0/3
A or B
A= ref $typeglobB= $typeglob =~ /::/
ABresult
1X1
011
000
31 ? $typeglob
32 : caller()."::$typeglob";
33 0 my $original;
34 {
35 0 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.2
36 $original = ref $typeglob eq 'CODE' && $typeglob
37 || *$typeglob{CODE}
38 0 ▶ || Carp::croak "Can't wrap non-existent subroutine ", $typeglob;
Condition0%0/7
ref $typeglob eq 'CODE' && $typeglob || *$typeglob{'CODE'} || Carp::croak(q[Can't wrap non-existent subroutine ], $typeglob)
l!l
00
ref $typeglob eq "CODE" and $typeglob or *$typeglob{"CODE"}
l!l
00
ref $typeglob eq "CODE" and $typeglob
!ll&&!rl&&r
000
MC/DC0%0/2
ref $typeglob eq 'CODE' && $typeglob || *$typeglob{'CODE'} || Carp::croak(q[Can't wrap non-existent subroutine ], $typeglob)
ref $typeglob eq "CODE" $typeglob
Truth table0%0/3
A and B
A= ref $typeglob eq "CODE"B= $typeglob
ABresult
111
0X0
100
39 }
40 Carp::croak "'$_' value is not a subroutine reference"
41 0 ▶ foreach grep {$wrapper{$_} && ref $wrapper{$_} ne 'CODE'}
Condition0%0/3
$wrapper{$_} && ref $wrapper{$_} ne 'CODE'
!ll&&!rl&&r
000
MC/DC0%0/2
$wrapper{$_} && ref $wrapper{$_} ne 'CODE'
$wrapper{$_} ref $wrapper{$_} ne 'CODE'
Truth table0%0/3
A && B
A= $wrapper{$_}B= ref $wrapper{$_} ne 'CODE'
ABresult
0X0
100
111
42 qw(pre post);
43 1 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
44 0 my ($caller, $unwrap) = *CORE::GLOBAL::caller{CODE};
45 0 ▶ my $imposter = sub {
Subroutine __ANON__: not called CC=16 SCAR=56.1
46 0 ▶ if ($unwrap) { goto &$original }
Branch: 1 branch
BranchTrueFalseTotal
if ($unwrap) 0 0 0
47 0 my ($return, $prereturn);
48 0 ▶ if (wantarray) {
Branch: 2 branches
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
elsif (defined wantarray) { } 0 0 0
49 0 $prereturn = $return = [];
50 0 ▶ () = $wrapper{pre}->(\@_,$return) if $wrapper{pre};
Branch: 1 branch
BranchTrueFalseTotal
if $wrapper{"pre"} 0 0 0
51 0 ▶ if (ref $return eq 'ARRAY' && $return == $prereturn && !@$return) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $return eq "ARRAY" and $return == $prereturn and not @$return) 0 0 0
Condition0%0/6
ref $return eq "ARRAY" and $return == $prereturn and not @$return
!ll&&!rl&&r
000
ref $return eq "ARRAY" and $return == $prereturn
!ll&&!rl&&r
000
MC/DC0%0/3
ref $return eq "ARRAY" and $return == $prereturn and not @$return
ref $return eq "ARRAY" $return == $prereturn not @$return
Truth table0%0/4
A and B and not(C)
A= ref $return eq "ARRAY"B= $return == $prereturnC= not @$return
ABCresult
0XX0
10X0
1100
1111
52 0 $return = [ &$original ];
53 () = $wrapper{post}->(@_, $return)
54 0 ▶ if $wrapper{post};
Branch: 1 branch
BranchTrueFalseTotal
if $wrapper{"post"} 0 0 0
55 }
56 0 ▶ return ref $return eq 'ARRAY' ? @$return : ($return);
Branch: 1 branch
BranchTrueFalseTotal
ref $return eq 'ARRAY' ? : 0 0 0
57 }
58 elsif (defined wantarray) {
59 0 ▶ $return = bless sub {$prereturn=1}, 'PerlGuard::Agent::LexWrap::Cleanup';
Subroutine __ANON__: not called CC=1 SCAR=6.9
60 0 ▶ my $dummy = $wrapper{pre}->(\@_, $return) if $wrapper{pre};
Branch: 1 branch
BranchTrueFalseTotal
if $wrapper{"pre"} 0 0 0
61 0 ▶ unless ($prereturn) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prereturn) 0 0 0
62 0 $return = &$original;
63 $dummy = scalar $wrapper{post}->(@_, $return)
64 0 ▶ if $wrapper{post};
Branch: 1 branch
BranchTrueFalseTotal
if $wrapper{"post"} 0 0 0
65 }
66 0 return $return;
67 }
68 else {
69 0 ▶ $return = bless sub {$prereturn=1}, 'PerlGuard::Agent::LexWrap::Cleanup';
Subroutine __ANON__: not called CC=1 SCAR=6.9
70 0 ▶ $wrapper{pre}->(\@_, $return) if $wrapper{pre};
Branch: 1 branch
BranchTrueFalseTotal
if $wrapper{"pre"} 0 0 0
71 0 ▶ unless ($prereturn) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prereturn) 0 0 0
72 0 &$original;
73 $wrapper{post}->(@_, $return)
74 0 ▶ if $wrapper{post};
Branch: 1 branch
BranchTrueFalseTotal
if $wrapper{"post"} 0 0 0
75 }
76 0 return;
77 }
78 0 };
79 0 ▶ ref $typeglob eq 'CODE' and return defined wantarray
Branch: 2 branches
BranchTrueFalseTotal
ref $typeglob eq "CODE" and return defined wantarray ? $imposter : Carp::carp("Uselessly wrapped subroutine reference in void context") 0 0 0
defined wantarray ? : 0 0 0
80 ? $imposter
81 : Carp::carp "Uselessly wrapped subroutine reference in void context";
82 {
83 0 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.2
84 0 *{$typeglob} = $imposter;
85 }
86 0 ▶ return unless defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 0 0
87 0 ▶ return bless sub{ $unwrap=1 }, 'PerlGuard::Agent::LexWrap::Cleanup';
Subroutine __ANON__: not called CC=1 SCAR=6.9
88 }
89  
90 package PerlGuard::Agent::LexWrap::Cleanup;
91  
92 0 ▶sub DESTROY { $_[0]->() }
Subroutine DESTROY: not called CC=1 SCAR=6.9
93 use overload
94 0 ▶ q{""} => sub { undef },
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=1 SCAR=6.9
95 0 ▶ q{0+} => sub { undef },
Subroutine __ANON__: not called CC=1 SCAR=6.9
96 0 ▶ q{bool} => sub { undef },
Subroutine __ANON__: not called CC=1 SCAR=6.9
97 1 q{fallback}=>1; #fallback=1 - like no overloading for other operations
98  
99 1 1;
100  
101 __END__
« Agent/Frameworks/Mojolicious.pm ↑ Summary Agent.pm »