blib/lib/HO/mixin.pm

filter: Statementstmt 87.9% 51 / 58 Branchbran 61.1% 11 / 18 Conditioncond 60.0% 9 / 15 MC/DCmcdc 22.2% 2 / 9 Subroutinesub 88.8% 8 / 9 Podpod n/a totaltotal 74.3% 81 / 109 SCAR 28.6
CC
15
Cov
78%
import
19.6
__ANON__
2.0
BEGIN
1.0
CRAP 17.4
« blib/lib/HO/class.pm ↑ Summary blib/lib/HO/abstract.pm »
1 package HO::mixin;
2 # ******************
3 1 our $VERSION = '0.02';
4 # ********************
5 1 ▶; use strict; use warnings
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶; use Carp ()
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶; use Package::Subroutine ()
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶; use Data::Dumper
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶; our $class
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 ; sub import
14 3 ▶ { my ($self, $mixin, @args) = @_
Subroutine import: called CC=15 SCAR=29.8
15 3 ▶ ; my $class = $HO::mixin::class || CORE::caller
Condition33%1/3
$HO::mixin::class || caller
l!l&&r!l&&!r
030
MC/DC0%0/2
$HO::mixin::class || caller
$HO::mixin::class caller
Truth table33%1/3
A || B
A= $HO::mixin::classB= caller
ABresult
1X1
011
000
16 3 ; my ($without,$only)
17 3 ▶ ; while(@args)
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 1 3 4
18 1 { my $arg = shift @args
19 1 ▶ ; if( $arg eq 'without' )
Branch: 1 branch
BranchTrueFalseTotal
if ($arg eq "without") 1 0 1
20 1 { my %skip = map { $_ => 1 } @{shift(@args)}
21 2 ▶ ; $without = sub { !$skip{$_[0]} }
Subroutine __ANON__: called CC=1 SCAR=0.0
22 1 }
23 1 ▶ ; if( $arg eq 'only' )
Branch: 1 branch
BranchTrueFalseTotal
if ($arg eq "only") 0 1 1
24 0 { my %only = map { $_ => 1 } @{shift(@args)}
25 0 ▶ ; $only = sub { $only{$_[0]} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
26 0 }
27 }
28 3 ▶ ; unless (defined $mixin)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $mixin) 0 3 3
29 0 { Carp::croak("Which class do you want to mix into ${self}?")
30 }
31 3 ▶ ; if($only && $without)
Branch: 1 branch
BranchTrueFalseTotal
if ($only and $without) 0 3 3
Condition33%1/3
$only and $without
!ll&&!rl&&r
300
MC/DC0%0/2
$only and $without
$only $without
Truth table33%1/3
A and B
A= $onlyB= $without
ABresult
0X0
100
111
32 0 { Carp::croak "Option 'without' and 'only' can't be used together in mixin $class."
33 }
34 3 ; eval "require $mixin"
35  
36 3 ▶ ; if($HO::class::class_args{$mixin})
Branch: 1 branch
BranchTrueFalseTotal
if ($HO::class::class_args{$mixin}) 3 0 3
37 { $HO::class::mixin_classes{$class} = [] unless
38 3 ▶ defined $HO::class::mixin_classes{$class}
Branch: 1 branch
BranchTrueFalseTotal
unless defined $HO::class::mixin_classes{$class} 3 0 3
39 3 ; push @{$HO::class::mixin_classes{$class}}, @{$HO::class::class_args{$mixin}}
40 }
41 2 ▶ ; my $filter = $only || $without || sub { 1 }
Subroutine __ANON__: called CC=1 SCAR=0.0
42  
43 3 ▶ ; $HO::accessor::classes{$class} = [] unless
Condition66%4/6
$only || $without || sub { 1; }
l!l&&r!l&&!r
120
$only or $without
l!l&&r!l&&!r
012
MC/DC0%0/3
$only || $without || sub { 1; }
$only $without sub { 1; }
Truth table50%2/4
A or B || C
A= $onlyB= $withoutC= sub { 1; }
ABCresult
1XX1
01X1
0011
0000
44 3 ▶ defined $HO::accessor::classes{$class}
Branch: 1 branch
BranchTrueFalseTotal
unless defined $HO::accessor::classes{$class} 1 2 3
45 3 ; my $mix = $HO::accessor::classes{$mixin}
46 3 ▶ ; $mix = [] unless ref $mix
Branch: 1 branch
BranchTrueFalseTotal
unless ref $mix 0 3 3
47 3 ; push @{$HO::accessor::classes{$class}}, @$mix
48 3 ; my %acc = @$mix
49 ; my @methods =
50 4 grep { $filter->($_) }
51 11 ▶ grep { !(/^(init|new)$/ || defined($acc{$_})) }
Condition100%3/3
/^(init|new)$/ || defined $acc{$_}
l!l&&r!l&&!r
344
MC/DC100%2/2
/^(init|new)$/ || defined $acc{$_}
/^(init|new)$/ defined $acc{$_}
Truth table100%3/3
A || B
A= /^(init|new)$/B= defined $acc{$_}
ABresult
1X1
011
000
52 3 grep { ! $HO::class::class_methods{$mixin}{$_} }
53 Package::Subroutine->findsubs( $mixin )
54 3 ; Package::Subroutine->export_to($class)->($mixin,@methods)
55 }
56  
57 1 ; 1
58  
59 __END__
« blib/lib/HO/class.pm ↑ Summary blib/lib/HO/abstract.pm »