Member/GLOB.pm

filter: Statementstmt 94.6% 89 / 94 Branchbran 77.2% 17 / 22 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 93.7% 15 / 16 Podpod n/a totaltotal 89.7% 123 / 137 CC 17 SCAR 14.7
CC
17
Cov
91%
import
8.1
__ANON__
7.0
__ANON__
3.0
CRAP 4.3
« Member/HASH.pm ↑ Summary Member/Dynamic.pm »
1 package Class::Member::GLOB;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 our $VERSION='1.6';
5  
6 2 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 my $get_class_members;
10 4 ▶$get_class_members=sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
11 4 my $pack=$_[0];
12 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 my %cm;
14 4 @cm{@{$pack.'::CLASS_MEMBERS'}}=();
15 4 foreach my $p (@{$pack.'::ISA'}) {
16 2 @cm{$get_class_members->($p)}=();
17 }
18 4 return keys %cm;
19 2 };
20  
21 3 ▶sub import {
Subroutine import: called CC=8 SCAR=20.9
22 3 my $pack=shift;
23 3 ($pack)=caller;
24  
25 26 ▶ my $getset=sub : lvalue {
Subroutine __ANON__: called CC=3 SCAR=11.0
26 26 my $I=shift;
27 26 my $what=shift;
28 26 ▶ unless( UNIVERSAL::isa( $I, 'GLOB' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($I, "GLOB")) 1 25 26
29 1 confess "$pack\::$what must be called as instance method\n";
30 }
31 25 $what=$pack.'::'.$what;
32 25 ▶ if( $#_>=0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ >= 0) 2 23 25
33 2 ${*$I}{$what}=shift;
34 }
35 25 ${*$I}{$what};
36 3 };
37  
38 2 ▶ my $new=sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
39 2 my $parent=shift;
40 2 ▶ my $class=ref($parent) || $parent;
Condition66%2/3
ref $parent || $parent
l!l&&r!l&&!r
110
MC/DC0%0/2
ref $parent || $parent
ref $parent $parent
Truth table66%2/3
A || B
A= ref $parentB= $parent
ABresult
1X1
011
000
41  
42 2 my $I=bless IO::Handle->new=>$class;
43 2 my %o=@_;
44 2 my @CLASS_MEMBERS=$get_class_members->($class);
45  
46 2 ▶ if( ref($parent) ) { # inherit first
Branch: 1 branch
BranchTrueFalseTotal
if (ref $parent) 1 1 2
47 1 foreach my $m (@CLASS_MEMBERS) {
48 3 $I->$m=$parent->$m;
49 }
50 }
51  
52 # then override with named parameters
53 2 foreach my $m (@CLASS_MEMBERS) {
54 6 ▶ $I->$m=$o{$m} if( exists $o{$m} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $o{$m} 3 3 6
55 }
56  
57 2 my $init=$I->can('I N I T');
58 2 ▶ if( $init ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($init) 2 0 2
59 2 $init=$init->();
60 2 $I->$init;
61 }
62  
63 2 return $I;
64 3 };
65  
66 3 foreach my $name (@_) {
67 10 ▶ if( $name=~/^-(.*)/ ) { # reserved name, aka option
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^-(.*)/) { } 5 5 10
68 5 my $o=$1;
69 5 ▶ if( $o eq 'CLASS_MEMBERS' ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($o eq 'CLASS_MEMBERS') { } 3 2 5
elsif ($o =~ /^NEW=(.+)/) { } 0 2 2
elsif ($o eq 'NEW') { } 1 1 2
elsif ($o =~ /^INIT=(.+)/) { } 1 0 1
elsif ($o eq 'INIT') { } 0 0 0
70 3 local $_;
71 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
72 3 *{$pack.'::CLASS_MEMBERS'}=[grep {!/^-/} @_];
73 } elsif( $o=~/^NEW=(.+)/ ) {
74 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
75 0 *{$pack.'::'.$1}=$new;
76 } elsif( $o eq 'NEW' ) {
77 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
78 1 *{$pack.'::new'}=$new;
79 } elsif( $o=~/^INIT=(.+)/ ) {
80 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
81 1 my $init="$1";
82 0 ▶ *{$pack.'::I N I T'}=sub(){$init};
Subroutine __ANON__: not called CC=1 SCAR=0.4
83 } elsif( $o eq 'INIT' ) {
84 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
85 0 *{$pack.'::I N I T'}=sub(){"init"};
86 }
87 } else {
88 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
89 5 ▶ *{$pack.'::'.$name}=sub:lvalue {
Subroutine __ANON__: called CC=1 SCAR=0.0
90 26 my $I=shift;
91 26 &{$getset}( $I, $name, @_ );
92 5 };
93 }
94 }
95 }
96  
97 2 1;
98  
99 __END__
« Member/HASH.pm ↑ Summary Member/Dynamic.pm »