Anonymous/Utils.pm

filter: Statementstmt 100% 56 / 56 Branchbran 68.1% 15 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 4 totaltotal 88.1% 82 / 93 CC 12 SCAR 9.0
CC
12
Cov
91%
around
3.1
before
3.0
after
3.0
CRAP 2.5
↑ Summary Anonymous.pm »
1 package Class::Anonymous::Utils;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 our @EXPORT_OK = qw/method before after around/;
10  
11 3 our %EXPORT_TAGS = (
12 all => \@EXPORT_OK,
13 );
14  
15 6 ▶sub method {
Subroutine method: called CC=2 SCAR=7.1
Pod undocumented
16 6 ▶ croak "'method' requires a name and a callback" unless @_ == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 6 6
17 6 my ($name, $cb) = @_;
18 6 $Class::Anonymous::CURRENT->($name => $cb);
19 }
20  
21 1 ▶sub before {
Subroutine before: called CC=3 SCAR=11.0
Pod undocumented
22 1 ▶ croak "'before' requires a name and a callback" unless @_ == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 1 1
23 1 my ($name, $cb) = @_;
24 1 my $old = $Class::Anonymous::CURRENT->($name);
25 1 ▶ croak "$name is not a method of the object" unless $old;
Branch: 1 branch
BranchTrueFalseTotal
unless $old 0 1 1
26 3 ▶ my $new = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
27 3 my $self = shift;
28 3 my $want = wantarray;
29 3 ▶ if ($want) {
Branch: 2 branches
BranchTrueFalseTotal
if ($want) { } 1 2 3
elsif (defined $want) { } 1 1 2
30 1 () = $self->$cb(@_);
31 1 return $self->$old(@_);
32 } elsif (defined $want) {
33 1 scalar $self->$cb(@_);
34 1 return $self->$old(@_);
35 } else {
36 1 $self->$cb(@_);
37 1 $self->$old(@_);
38 }
39 1 };
40 1 $Class::Anonymous::CURRENT->($name => $new);
41 }
42  
43 1 ▶sub after {
Subroutine after: called CC=3 SCAR=11.0
Pod undocumented
44 1 ▶ croak "'after' requires a name and a callback" unless @_ == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 1 1
45 1 my ($name, $cb) = @_;
46 1 my $old = $Class::Anonymous::CURRENT->($name);
47 1 ▶ croak "$name is not a method of the object" unless $old;
Branch: 1 branch
BranchTrueFalseTotal
unless $old 0 1 1
48 3 ▶ my $new = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
49 3 my $self = shift;
50 3 my $want = wantarray;
51 3 ▶ if ($want) {
Branch: 2 branches
BranchTrueFalseTotal
if ($want) { } 1 2 3
elsif (defined $want) { } 1 1 2
52 1 my @ret = $self->$old(@_);
53 1 () = $self->$cb(@_);
54 1 return @ret;
55 } elsif (defined $want) {
56 1 my $ret = $self->$old(@_);
57 1 scalar $self->$cb(@_);
58 1 return $ret;
59 } else {
60 1 $self->$old(@_);
61 1 $self->$cb(@_);
62 }
63 1 };
64 1 $Class::Anonymous::CURRENT->($name => $new);
65 }
66  
67 2 ▶sub around {
Subroutine around: called CC=3 SCAR=11.2
Pod undocumented
68 2 ▶ croak "'around' requires a name and a callback" unless @_ == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 2 2
69 2 my ($name, $cb) = @_;
70 2 my $old = $Class::Anonymous::CURRENT->($name);
71 2 ▶ croak "$name is not a method of the object" unless $old;
Branch: 1 branch
BranchTrueFalseTotal
unless $old 0 2 2
72 2 ▶ $Class::Anonymous::CURRENT->($name => sub { $cb->($old, @_) });
Subroutine __ANON__: called CC=1 SCAR=0.0
73 }
74  
75 3 1;
76  
↑ Summary Anonymous.pm »