Gloom.pm

filter: Statementstmt 80.4% 103 / 128 Branchbran 56.5% 26 / 46 Conditioncond 45.0% 9 / 20 MC/DCmcdc 9.0% 1 / 11 Subroutinesub 82.6% 19 / 23 Podpod 0.0% 0 / 11 totaltotal 66.1% 158 / 239 CC 32 SCAR 23.4
CC
32
Cov
71%
has
26.9
__ANON__
11.3
import
4.0
CRAP 10.4
↑ Summary Module/Install/Gloom.pm »
1 ### This module was derived from Gloom - the Great Little OO Module!
2 ### Read `perldoc Gloom` for more information.
3  
4 3 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
5 package Gloom;
6 3 our $VERSION = '0.25';
7  
8 3 ▶use constant XXX_skip => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 ▶sub import {
Subroutine import: called CC=4 SCAR=13.9
11 6 my ($class, $flag) = @_;
12 6 my ($package, $module) = caller(0);
13  
14 6 strict->import;
15 6 warnings->import;
16  
17 6 ▶ if ($class->isa(__PACKAGE__) and
Branch: 1 branch
BranchTrueFalseTotal
if ($class->isa(__PACKAGE__) and defined $flag and $flag eq '-base') { } 4 2 6
Condition66%4/6
$class->isa(__PACKAGE__) and defined $flag and $flag eq "-base"
!ll&&!rl&&r
204
$class->isa(__PACKAGE__) and defined $flag
!ll&&!rl&&r
024
MC/DC33%1/3
$class->isa(__PACKAGE__) and defined $flag and $flag eq "-base"
$class->isa(__PACKAGE__) defined $flag $flag eq "-base"
Truth table50%2/4
A and B and C
A= $class->isa(__PACKAGE__)B= defined $flagC= $flag eq "-base"
ABCresult
0XX0
10X0
1100
1111
18 defined $flag and
19 $flag eq '-base'
20 ) {
21 4 $class->import_base($package, $module);
22 }
23 else {
24 2 require Exporter;
25 2 goto &Exporter::import;
26 }
27 }
28  
29 4 ▶sub import_base {
Subroutine import_base: called CC=1 SCAR=0.0
Pod undocumented
30 4 my ($class, $package, $module) = @_;
31 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 4 push @{$package . '::ISA'}, $class;
33 4 $class->import_fake($package, $module);
34 4 $class->export_base($package);
35 }
36  
37 4 ▶sub import_fake {
Subroutine import_fake: called CC=2 SCAR=6.9
Pod undocumented
38 4 my ($class, $package, $module) = @_;
39 4 my $inc_module = $package . '.pm';
40 4 $inc_module =~ s/::/\//g;
41 4 ▶ return if defined $INC{$inc_module};
Branch: 1 branch
BranchTrueFalseTotal
if defined $INC{$inc_module} 1 3 4
42 3 $INC{$inc_module} = $module;
43 }
44  
45 4 ▶sub export_base {
Subroutine export_base: called CC=3 SCAR=11.0
Pod undocumented
46 4 my ($source, $target) = @_;
47 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
48 4 for my $sub (map {
49 20 ▶ /::/ ? $_ : "${source}::$_"
Branch: 1 branch
BranchTrueFalseTotal
/::/ ? : 20 0 20
50 } $source->EXPORT_BASE()) {
51 20 my $name = $sub;
52 20 $name =~ s/.*:://;
53 20 *{$target . "::$name"} = \&$sub;
54 }
55 }
56  
57 2 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
58 2 my $class = shift;
59 2 my $self = bless {}, $class;
60 2 $self->init(@_);
61 2 return $self;
62 }
63  
64 2 ▶sub init {
Subroutine init: called CC=3 SCAR=12.3
Pod undocumented
65 2 my $self = shift;
66 2 ▶ while (my ($property, $value) = splice(@_, 0, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 3 2 5
67 3 ▶ unless ($self->can($property)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->can($property)) 0 3 3
68 0 my $class = ref $self;
69 0 require Carp;
70 0 Carp::confess("Class '$class' has no property '$property'");
71 }
72 3 $self->$property($value);
73 }
74 }
75  
76 3 my %code = (
77 sub_start =>
78 "sub {\n",
79 set_default =>
80 " \$_[0]->{%s} = %s\n unless exists \$_[0]->{%s};\n",
81 class =>
82 " return do { my \$class = \$_[0]; %s } unless ref \$_[0];\n",
83 init =>
84 " return \$_[0]->{%s} = do { my \$self = \$_[0]; %s }\n" .
85 " unless \$#_ > 0 or defined \$_[0]->{%s};\n",
86 return_if_get =>
87 " return \$_[0]->{%s} unless \$#_ > 0;\n",
88 set =>
89 " \$_[0]->{%s} = \$_[1];\n",
90 onset =>
91 " do { local \$_ = \$_[1]; my \$self = \$_[0]; %s };\n",
92 chain =>
93 " return \$_[0];\n}\n",
94 sub_end =>
95 " return \$_[0]->{%s};\n}\n",
96 );
97  
98 2 ▶my $parse_arguments = sub {
Subroutine __ANON__: called CC=8 SCAR=24.2
99 2 ▶ my $paired_arguments = shift || [];
Condition50%1/2
shift() || []
l!l
20
MC/DC0%0/1
shift() || []
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
100 2 my ($args, @values) = ({}, ());
101 2 my %pairs = map { ($_, 1) } @$paired_arguments;
102 2 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 2 4
103 2 my $elem = shift;
104 2 ▶ if (defined $elem and defined $pairs{$elem} and @_) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $elem and defined $pairs{$elem} and @_) { } 0 2 2
elsif ($elem eq '-chain') { } 0 2 2
Condition33%2/6
defined $elem and defined $pairs{$elem} and @_
!ll&&!rl&&r
200
defined $elem and defined $pairs{$elem}
!ll&&!rl&&r
020
MC/DC0%0/3
defined $elem and defined $pairs{$elem} and @_
defined $elem defined $pairs{$elem} @_
Truth table25%1/4
A and B and C
A= defined $elemB= defined $pairs{$elem}C= @_
ABCresult
0XX0
10X0
1100
1111
105 0 $args->{$elem} = shift;
106 }
107 elsif ($elem eq '-chain') {
108 0 $args->{-chain} = 1;
109 }
110 else {
111 2 push @values, $elem;
112 }
113 }
114 2 ▶ return wantarray ? ($args, @values) : $args;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 0 2
115 3 };
116  
117 2 ▶my $default_as_code = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
118 3 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
119 2 require Data::Dumper;
120 2 local $Data::Dumper::Sortkeys = 1;
121 2 my $code = Data::Dumper::Dumper(shift);
122 2 $code =~ s/^\$VAR1 = //;
123 2 $code =~ s/;$//;
124 2 return $code;
125 3 };
126  
127 2 ▶sub has {
Subroutine has: called CC=15 SCAR=32.9
Pod undocumented
128 2 my $package = caller;
129 2 my ($args, @values) = &$parse_arguments(
130 [ qw(-package -class -init -onset) ],
131 @_,
132 );
133 2 my ($has, $default) = @values;
134 2 ▶ $package = $args->{-package} if defined $args->{-package};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"-package"} 0 2 2
135 2 ▶ return if defined &{"${package}::$has"};
Branch: 1 branch
BranchTrueFalseTotal
if defined &{"${package}::$has";} 0 2 2
136 2 ▶ my $default_string =
Branch: 2 branches
BranchTrueFalseTotal
ref $default eq 'ARRAY' && !@$default ? : 0 2 2
ref $default eq 'HASH' && !keys(%$default) ? : 0 2 2
Condition33%2/6
ref $default eq "ARRAY" and not @$default
!ll&&!rl&&r
200
ref $default eq "HASH" and not keys %$default
!ll&&!rl&&r
200
MC/DC0%0/2
ref $default eq "ARRAY" and not @$default
ref $default eq "ARRAY" not @$default
MC/DC0%0/2
ref $default eq "HASH" and not keys %$default
ref $default eq "HASH" not keys %$default
Truth table33%1/3
A and not(B)
A= ref $default eq "ARRAY"B= not @$default
ABresult
0X0
100
111
Truth table33%1/3
A and not(B)
A= ref $default eq "HASH"B= not keys %$default
ABresult
0X0
100
111
137 ( ref($default) eq 'ARRAY' and not @$default )
138 ? '[]'
139 : (ref($default) eq 'HASH' and not keys %$default )
140 ? '{}'
141 : &$default_as_code($default);
142  
143 2 my $code = $code{sub_start};
144  
145 2 ▶ if ($args->{-class}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"-class"}) 0 2 2
146 0 ▶ if ($args->{-class} eq '-init') {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"-class"} eq "-init") 0 0 0
147 0 $args->{-class} = $args->{-init};
148 0 $args->{-class} =~ s/\$self/\$class/g;
149 }
150 0 my $fragment = $code{class};
151 $code .= sprintf
152 $fragment,
153 0 $args->{-class};
154 }
155  
156 2 ▶ if ($args->{-init}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"-init"}) 0 2 2
157 0 my $fragment = $code{init};
158 $code .= sprintf
159 $fragment,
160 $has,
161 $args->{-init},
162 0 ($has) x 4;
163 }
164 2 ▶ $code .= sprintf $code{set_default}, $has, $default_string, $has
Branch: 1 branch
BranchTrueFalseTotal
if defined $default 0 2 2
165 if defined $default;
166 2 $code .= sprintf $code{return_if_get}, $has;
167 2 $code .= sprintf $code{set}, $has;
168 $code .= sprintf $code{onset}, $args->{-onset}
169 2 ▶ if defined $args->{-onset};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"-onset"} 0 2 2
170 2 ▶ if (defined $args->{-chain}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{'-chain'}) { } 0 2 2
171 0 $code .= $code{chain};
172 }
173 else {
174 2 $code .= sprintf $code{sub_end}, $has;
175 }
176  
177 2 ▶ my $sub = eval $code;
Subroutine __ANON__: called CC=2 SCAR=7.1
Subroutine __ANON__: called CC=2 SCAR=7.1
Branch: 2 branches
BranchTrueFalseTotal
unless $#_ > 0 0 2 2
unless $#_ > 0 0 1 1
178 2 ▶ die "eval('$code') failed: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
179 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
180 2 *{"${package}::$has"} = $sub;
181 2 ▶ return $code if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 0 2 2
182 }
183  
184 3 our $DumpModule = 'YAML::XS';
185 0 ▶sub WWW { require XXX; local $XXX::DumpModule = $DumpModule; XXX::WWW(@_) }
Subroutine WWW: not called CC=1 SCAR=6.9
Pod undocumented
186 0 ▶sub XXX { require XXX; local $XXX::DumpModule = $DumpModule; XXX::XXX(@_) }
Subroutine XXX: not called CC=1 SCAR=6.9
Pod undocumented
187 0 ▶sub YYY { require XXX; local $XXX::DumpModule = $DumpModule; XXX::YYY(@_) }
Subroutine YYY: not called CC=1 SCAR=6.9
Pod undocumented
188 0 ▶sub ZZZ { require XXX; local $XXX::DumpModule = $DumpModule; XXX::ZZZ(@_) }
Subroutine ZZZ: not called CC=1 SCAR=6.9
Pod undocumented
189  
190 4 ▶sub EXPORT_BASE {
Subroutine EXPORT_BASE: called CC=1 SCAR=0.0
Pod undocumented
191 4 return map { __PACKAGE__ . '::' .$_ }
192 qw(has WWW XXX YYY ZZZ);
193 }
↑ Summary Module/Install/Gloom.pm »