blib/lib/Class/Accessor/Array/Glob.pm

filter: Statementstmt 91.8% 68 / 74 Branchbran 50.0% 18 / 36 Conditioncond 80.0% 8 / 10 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 80.0% 12 / 15 Podpod n/a totaltotal 78.0% 110 / 141 CC 25 SCAR 23.4
CC
25
Cov
78%
import
21.3
__ANON__
2.3
__ANON__
2.3
CRAP 10.4
↑ Summary
1 package Class::Accessor::Array::Glob;
2  
3 1 our $DATE = '2016-03-29'; # DATE
4 1 our $VERSION = '0.01'; # VERSION
5  
6 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use strict 'subs', 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶sub import {
Subroutine import: called CC=17 SCAR=30.6
11 2 my ($class0, $spec) = @_;
12 2 my $caller = caller();
13  
14 2 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 my $max_idx;
17 2 for (values %{$spec->{accessors}}) {
18 8 ▶ $max_idx = $_ if !defined($max_idx) || $max_idx < $_;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $max_idx or $max_idx < $_ 3 5 8
Condition100%3/3
not defined $max_idx or $max_idx < $_
l!l&&r!l&&!r
215
MC/DC100%2/2
not defined $max_idx or $max_idx < $_
not defined $max_idx $max_idx < $_
Truth table100%3/3
not(A) or B
A= not defined $max_idxB= $max_idx < $_
ABresult
1X1
011
000
19 }
20  
21 2 my $glob_attribute = $spec->{glob_attribute};
22  
23 # generate accessors
24 2 for my $meth (keys %{$spec->{accessors}}) {
25 8 my $idx = $spec->{accessors}{$meth};
26 8 my $is = 'rw';
27 8 ▶ my $code_str = $is eq 'rw' ? 'sub (;$) { ' : 'sub () { ';
Branch: 1 branch
BranchTrueFalseTotal
$is eq 'rw' ? : 8 0 8
28 8 ▶ if (defined($glob_attribute) && $glob_attribute eq $meth) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $glob_attribute and $glob_attribute eq $meth) { } 1 7 8
Condition100%3/3
defined $glob_attribute and $glob_attribute eq $meth
!ll&&!rl&&r
341
MC/DC100%2/2
defined $glob_attribute and $glob_attribute eq $meth
defined $glob_attribute $glob_attribute eq $meth
Truth table100%3/3
A and B
A= defined $glob_attributeB= $glob_attribute eq $meth
ABresult
0X0
100
111
29 1 ▶ die "Glob attribute must be put at the last index"
Branch: 1 branch
BranchTrueFalseTotal
unless $idx == $max_idx 0 1 1
30 unless $idx == $max_idx;
31 1 ▶ $code_str .= "splice(\@{\$_[0]}, $idx, scalar(\@{\$_[0]}), \@{\$_[1]}) if \@_ > 1; "
Branch: 1 branch
BranchTrueFalseTotal
if $is eq "rw" 1 0 1
32 if $is eq 'rw';
33 1 $code_str .= "[ \@{\$_[0]}[$idx .. \$#{\$_[0]}] ]; ";
34 } else {
35 7 ▶ $code_str .= "\$_[0][$idx] = \$_[1] if \@_ > 1; "
Branch: 1 branch
BranchTrueFalseTotal
if $is eq "rw" 7 0 7
36 if $is eq 'rw';
37 7 $code_str .= "\$_[0][$idx]; ";
38 }
39 8 $code_str .= "}";
40 #say "D:accessor code for $meth: ", $code_str;
41 0 ▶ *{"$caller\::$meth"} = eval $code_str;
Subroutine __ANON__: not called CC=2 SCAR=8.5
Subroutine __ANON__: called CC=2 SCAR=8.5
Subroutine __ANON__: not called CC=2 SCAR=8.5
Subroutine __ANON__: called CC=2 SCAR=8.5
Subroutine __ANON__: not called CC=2 SCAR=8.5
Subroutine __ANON__: called CC=2 SCAR=8.5
Subroutine __ANON__: called CC=2 SCAR=8.5
Subroutine __ANON__: called CC=2 SCAR=8.5
Branch: 8 branches
BranchTrueFalseTotal
if @_ > 1 0 0 0
if @_ > 1 1 0 1
if @_ > 1 0 0 0
if @_ > 1 1 0 1
if @_ > 1 0 0 0
if @_ > 1 1 0 1
if @_ > 1 1 0 1
if @_ > 1 1 0 1
42 8 ▶ die if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 8 8
43 }
44  
45 # generate constructor
46 {
47 2 ▶ my $n = ($max_idx // 0) + 1; $n-- if defined $glob_attribute;
Branch: 1 branch
BranchTrueFalseTotal
if defined $glob_attribute 1 1 2
Condition50%1/2
$max_idx // 0
l!l
20
MC/DC0%0/1
$max_idx // 0
$max_idx
Truth table50%1/2
A
A= $max_idx
Aresult
11
00
48 2 my $code_str = 'sub { my $class = shift; bless [(undef) x '.$n.'], $class }';
49  
50 #say "D:constructor code for class $caller: ", $code_str;
51 2 ▶ my $constructor = $spec->{constructor} || "new";
Condition50%1/2
$spec->{'constructor'} || 'new'
l!l
02
MC/DC0%0/1
$spec->{'constructor'} || 'new'
$spec->{'constructor'}
Truth table50%1/2
A
A= $spec->{'constructor'}
Aresult
11
00
52 2 ▶ unless (*{"$caller\::$constructor"}{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (*{"${caller}::$constructor";}{"CODE"}) 2 0 2
53 2 ▶ *{"$caller\::$constructor"} = eval $code_str;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
54 2 ▶ die if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
55 };
56 }
57 }
58  
59 1 1;
60 # ABSTRACT: Generate accessors/constructor for array-based object (supports globbing attribute)
61  
62 __END__
↑ Summary