Yath/HashBase.pm

filter: Statementstmt 90.1% 155 / 172 Branchbran 75.0% 57 / 76 Conditioncond 52.3% 11 / 21 MC/DCmcdc 16.6% 2 / 12 Subroutinesub 84.0% 21 / 25 Podpod 25.0% 1 / 4 totaltotal 79.6% 247 / 310 CC 52 SCAR 22.9
CC
52
Cov
83%
args_to_subs
20.0
do_import
14.0
__ANON__
10.0
CRAP 9.9
« Yath/Term.pm ↑ Summary Yath/Settings/Group.pm »
1 package Getopt::Yath::HashBase;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 our $VERSION = '2.000007';
6  
7 #################################################################
8 # #
9 # This is a generated file! Do not modify this file directly! #
10 # Use hashbase_inc.pl script to regenerate this file. #
11 # The script is part of the Object::HashBase distribution. #
12 # Note: You can modify the version number above this comment #
13 # if needed, that is fine. #
14 # #
15 #################################################################
16  
17 {
18 2 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 $Getopt::Yath::HashBase::HB_VERSION = '0.015';
20 2 *Getopt::Yath::HashBase::ATTR_SUBS = \%Object::HashBase::ATTR_SUBS;
21 2 *Getopt::Yath::HashBase::ATTR_LIST = \%Object::HashBase::ATTR_LIST;
22 2 *Getopt::Yath::HashBase::VERSION = \%Object::HashBase::VERSION;
23 2 *Getopt::Yath::HashBase::CAN_CACHE = \%Object::HashBase::CAN_CACHE;
24 }
25  
26  
27 2 require Carp;
28 {
29 2 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 2 $Carp::Internal{+__PACKAGE__} = 1;
31 }
32  
33 BEGIN {
34 {
35 # Make sure none of these get messed up.
36 2 ▶ local ($SIG{__DIE__}, $@, $?, $!, $^E);
Subroutine BEGIN: called CC=4 SCAR=16.8
37 2 ▶ if (eval { require Class::XSAccessor; Class::XSAccessor->VERSION(1.19); 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Class::XSAccessor; 'Class::XSAccessor'->VERSION(1.19); 1 } }) { } 2 0 2
38 *CLASS_XS_ACCESSOR = sub() { 1 }
39 2 }
40 else {
41 *CLASS_XS_ACCESSOR = sub() { 0 }
42 0 }
43 }
44  
45 # these are not strictly equivalent, but for out use we don't care
46 # about order
47 *_isa = ($] >= 5.010 && require mro) ? \&mro::get_linear_isa : sub {
48 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
49 0 ▶ my @packages = ($_[0]);
Subroutine __ANON__: not called CC=2 SCAR=17.9
50 0 my %seen;
51 0 for my $package (@packages) {
52 0 push @packages, grep !$seen{$_}++, @{"$package\::ISA"};
53 }
54 0 return \@packages;
55 }
56 2 ▶}
Branch: 1 branch
BranchTrueFalseTotal
$] >= 5.01 && require mro ? : 2 0 2
Condition33%1/3
$] >= "5.01" and require mro
!ll&&!rl&&r
002
MC/DC0%0/2
$] >= "5.01" and require mro
$] >= "5.01" require mro
Truth table33%1/3
A and B
A= $] >= "5.01"B= require mro
ABresult
0X0
100
111
57  
58 2 my %SPEC = (
59 '^' => {reader => 1, writer => 0, dep_writer => 1, read_only => 0, strip => 1},
60 '-' => {reader => 1, writer => 0, dep_writer => 0, read_only => 1, strip => 1},
61 '>' => {reader => 0, writer => 1, dep_writer => 0, read_only => 0, strip => 1},
62 '<' => {reader => 1, writer => 0, dep_writer => 0, read_only => 0, strip => 1},
63 '+' => {reader => 0, writer => 0, dep_writer => 0, read_only => 0, strip => 1},
64 '~' => {reader => 1, writer => 1, dep_writer => 0, read_only => 0, strip => 1, no_xs => 1},
65 );
66  
67 73 ▶sub spec { \%SPEC }
Subroutine spec: called CC=1 SCAR=0.0
Pod undocumented
68  
69 sub import {
70 21 ▶ my $class = shift;
Subroutine import: called CC=1 SCAR=0.0
71 21 my $into = caller;
72 21 $class->do_import($into, @_);
73 }
74  
75 sub do_import {
76 21 ▶ my $class = shift;
Subroutine do_import: called CC=13 SCAR=26.4
Pod undocumented
77 21 my $into = shift;
78  
79 # Make sure we list the OLDEST version used to create this class.
80 21 ▶ my $ver = $Getopt::Yath::HashBase::HB_VERSION || $Getopt::Yath::HashBase::VERSION;
Condition33%1/3
$Getopt::Yath::HashBase::HB_VERSION || $Getopt::Yath::HashBase::VERSION
l!l&&r!l&&!r
2100
MC/DC0%0/2
$Getopt::Yath::HashBase::HB_VERSION || $Getopt::Yath::HashBase::VERSION
$Getopt::Yath::HashBase::HB_VERSION $Getopt::Yath::HashBase::VERSION
Truth table33%1/3
A || B
A= $Getopt::Yath::HashBase::HB_VERSIONB= $Getopt::Yath::HashBase::VERSION
ABresult
1X1
011
000
81 21 ▶ $Getopt::Yath::HashBase::VERSION{$into} = $ver if !$Getopt::Yath::HashBase::VERSION{$into} || $Getopt::Yath::HashBase::VERSION{$into} > $ver;
Branch: 1 branch
BranchTrueFalseTotal
if not $Getopt::Yath::HashBase::VERSION{$into} or $Getopt::Yath::HashBase::VERSION{$into} > $ver 21 0 21
Condition33%1/3
not $Getopt::Yath::HashBase::VERSION{$into} or $Getopt::Yath::HashBase::VERSION{$into} > $ver
l!l&&r!l&&!r
2100
MC/DC0%0/2
not $Getopt::Yath::HashBase::VERSION{$into} or $Getopt::Yath::HashBase::VERSION{$into} > $ver
not $Getopt::Yath::HashBase::VERSION{$into} $Getopt::Yath::HashBase::VERSION{$into} > $ver
Truth table33%1/3
not(A) or B
A= not $Getopt::Yath::HashBase::VERSION{$into}B= $Getopt::Yath::HashBase::VERSION{$into} > $ver
ABresult
1X1
011
000
82  
83 21 my $isa = _isa($into);
84 21 ▶ my $attr_list = $Getopt::Yath::HashBase::ATTR_LIST{$into} ||= [];
Condition50%1/2
$Getopt::Yath::HashBase::ATTR_LIST{$into} ||= []
l!l
021
MC/DC0%0/1
$Getopt::Yath::HashBase::ATTR_LIST{$into} ||= []
$Getopt::Yath::HashBase::ATTR_LIST{$into}
Truth table50%1/2
A
A= $Getopt::Yath::HashBase::ATTR_LIST{$into}
Aresult
11
00
85 21 ▶ my $attr_subs = $Getopt::Yath::HashBase::ATTR_SUBS{$into} ||= {};
Condition50%1/2
$Getopt::Yath::HashBase::ATTR_SUBS{$into} ||= {}
l!l
021
MC/DC0%0/1
$Getopt::Yath::HashBase::ATTR_SUBS{$into} ||= {}
$Getopt::Yath::HashBase::ATTR_SUBS{$into}
Truth table50%1/2
A
A= $Getopt::Yath::HashBase::ATTR_SUBS{$into}
Aresult
11
00
86  
87 21 my @pre_init;
88 my @post_init;
89  
90 21 my $add_new = 1;
91  
92 21 ▶ if (my $have_new = $into->can('new')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $have_new = $into->can("new")) 12 9 21
93 12 ▶ my $new_lookup = $Getopt::Yath::HashBase::NEW_LOOKUP //= {};
Condition50%1/2
$Getopt::Yath::HashBase::NEW_LOOKUP //= {}
l!l
120
MC/DC0%0/1
$Getopt::Yath::HashBase::NEW_LOOKUP //= {}
$Getopt::Yath::HashBase::NEW_LOOKUP
Truth table50%1/2
A
A= $Getopt::Yath::HashBase::NEW_LOOKUP
Aresult
11
00
94 12 ▶ $add_new = 0 unless $new_lookup->{$have_new};
Branch: 1 branch
BranchTrueFalseTotal
unless $new_lookup->{$have_new} 1 11 12
95 }
96  
97 my %subs = (
98 ($add_new ? ($class->_build_new($into, \@pre_init, \@post_init)) : ()),
99 21 ▶ (map %{$Getopt::Yath::HashBase::ATTR_SUBS{$_} || {}}, @{$isa}[1 .. $#$isa]),
Branch: 2 branches
BranchTrueFalseTotal
$add_new ? : 20 1 21
$Getopt::Yath::HashBase::ATTR_SUBS{$_} or {} 0 14 14
100 ($class->args_to_subs($attr_list, $attr_subs, \@_, $into)),
101 );
102  
103 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
104 21 ▶ while (my ($k, $v) = each %subs) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %subs) 544 21 565
105 544 ▶ if (ref($v) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq 'CODE') { } 458 86 544
106 458 *{"$into\::$k"} = $v;
107 }
108 else {
109 86 my ($sub, @args) = @$v;
110 86 $sub->(@args);
111 }
112 }
113 }
114  
115 sub args_to_subs {
116 21 ▶ my $class = shift;
Subroutine args_to_subs: called CC=16 SCAR=30.0
Pod undocumented
117 21 my ($attr_list, $attr_subs, $args, $into) = @_;
118  
119 21 my $use_gen = $class->can('gen_accessor') ;
120  
121 21 my %out;
122  
123 21 ▶ while (@$args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$args) 73 21 94
124 73 my $x = shift @$args;
125 73 my $p = substr($x, 0, 1);
126  
127 73 ▶ my $spec = $class->spec->{$p} || {reader => 1, writer => 1};
Condition100%2/2
$class->spec->{$p} || {'reader', 1, 'writer', 1}
l!l
5122
MC/DC100%1/1
$class->spec->{$p} || {'reader', 1, 'writer', 1}
$class->spec->{$p}
Truth table100%2/2
A
A= $class->spec->{$p}
Aresult
11
00
128 73 ▶ substr($x, 0, 1) = '' if $spec->{strip};
Branch: 1 branch
BranchTrueFalseTotal
if $spec->{"strip"} 51 22 73
129  
130 73 push @$attr_list => $x;
131 73 my ($sub, $attr) = (uc $x, $x);
132  
133 73 ▶ $attr_subs->{$sub} = sub() { $attr };
Subroutine __ANON__: not called CC=1 SCAR=1.2
134 73 $out{$sub} = $attr_subs->{$sub};
135  
136 73 my $copy = "$attr";
137 73 ▶ if ($spec->{reader}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{"reader"}) 63 10 73
138 63 ▶ if ($use_gen) {
Branch: 2 branches
BranchTrueFalseTotal
if ($use_gen) { } 0 63 63
elsif (not $spec->{'no_xs'}) { } 63 0 63
139 0 $out{$attr} = $class->gen_accessor(reader => $copy, $spec, $args);
140 }
141 elsif (CLASS_XS_ACCESSOR && !$spec->{no_xs}) {
142 63 $out{$attr} = [\&Class::XSAccessor::newxs_getter, "$into\::$attr", $copy];
143 }
144 else {
145 0 ▶ $out{$attr} = sub { $_[0]->{$attr} };
Subroutine __ANON__: not called CC=1 SCAR=6.9
146 }
147 }
148  
149 73 ▶ if ($spec->{writer}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($spec->{'writer'}) { } 23 50 73
elsif ($spec->{'read_only'}) { } 1 49 50
elsif ($spec->{'dep_writer'}) { } 1 48 49
150 23 ▶ if ($use_gen) {
Branch: 2 branches
BranchTrueFalseTotal
if ($use_gen) { } 0 23 23
elsif (not $spec->{'no_xs'}) { } 23 0 23
151 0 $out{"set_$attr"} = $class->gen_accessor(writer => $copy, $spec, $args);
152 }
153 elsif(CLASS_XS_ACCESSOR && !$spec->{no_xs}) {
154 23 $out{"set_$attr"} = [\&Class::XSAccessor::newxs_setter, "$into\::set_$attr", $copy, 0];
155 }
156 else {
157 0 ▶ $out{"set_$attr"} = sub { $_[0]->{$attr} = $_[1] };
Subroutine __ANON__: not called CC=1 SCAR=6.9
158 }
159 }
160 elsif($spec->{read_only}) {
161 1 ▶ $out{"set_$attr"} = $use_gen ? $class->gen_accessor(read_only => $copy, $spec, $args) : sub { Carp::croak("'$attr' is read-only") };
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
$use_gen ? : 0 1 1
162 }
163 elsif($spec->{dep_writer}) {
164 1 ▶ $out{"set_$attr"} = $use_gen ? $class->gen_accessor(dep_writer => $copy, $spec, $args) : sub { Carp::carp("set_$attr() is deprecated"); $_[0]->{$attr} = $_[1] };
Subroutine __ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
$use_gen ? : 0 1 1
165 }
166  
167 73 ▶ if ($spec->{custom}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{"custom"}) 0 73 73
168 0 my %add = $class->gen_accessor(custom => $copy, $spec, $args);
169 0 $out{$_} = $add{$_} for keys %add;
170 }
171 }
172  
173 21 return %out;
174 }
175  
176 sub attr_list {
177 3 ▶ my $class = shift;
Subroutine attr_list: called CC=4 SCAR=14.3
Pod documented
178  
179 3 my $isa = _isa($class);
180  
181 3 my %seen;
182 15 my @list = grep { !$seen{$_}++ } map {
183 3 my @out;
184  
185 6 ▶ if (0.004 > ($Getopt::Yath::HashBase::VERSION{$_} || 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (0.004 > ($Getopt::Yath::HashBase::VERSION{$_} || 0)) { } 0 6 6
Condition50%1/2
$Getopt::Yath::HashBase::VERSION{$_} || 0
l!l
60
MC/DC0%0/1
$Getopt::Yath::HashBase::VERSION{$_} || 0
$Getopt::Yath::HashBase::VERSION{$_}
Truth table50%1/2
A
A= $Getopt::Yath::HashBase::VERSION{$_}
Aresult
11
00
186 0 Carp::carp("$_ uses an inlined version of Getopt::Yath::HashBase too old to support attr_list()");
187 }
188 else {
189 6 my $list = $Getopt::Yath::HashBase::ATTR_LIST{$_};
190 6 ▶ @out = $list ? @$list : ()
Branch: 1 branch
BranchTrueFalseTotal
$list ? : 6 0 6
191 }
192  
193 6 @out;
194 } reverse @$isa;
195  
196 3 return @list;
197 }
198  
199 sub _build_new {
200 20 ▶ my $class = shift;
Subroutine _build_new: called CC=9 SCAR=22.0
201 20 my ($into, $pre_init, $post_init) = @_;
202  
203 20 ▶ my $add_pre_init = sub(&) { push @$pre_init => $_[-1] };
Subroutine __ANON__: called CC=1 SCAR=0.0
204 20 ▶ my $add_post_init = sub(&) { push @$post_init => $_[-1] };
Subroutine __ANON__: called CC=1 SCAR=0.0
205  
206 20 my $__pre_init = $into->can('_pre_init');
207 20 ▶ my $_pre_init = $__pre_init ? sub { ($__pre_init->(), @$pre_init) } : sub { @$pre_init };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$__pre_init ? : 11 9 20
208  
209 20 my $__post_init = $into->can('_post_init');
210 20 ▶ my $_post_init = $__post_init ? sub { ($__post_init->(), @$post_init) } : sub { @$post_init };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$__post_init ? : 11 9 20
211  
212 my $new = sub {
213 30 ▶ my $class = shift;
Subroutine __ANON__: called CC=10 SCAR=23.0
214  
215 30 my $self;
216  
217 30 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 3 27 30
218 3 my $arg = shift;
219 3 my $type = ref($arg);
220  
221 3 ▶ if ($type eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'HASH') { } 1 2 3
222 1 $self = bless({%$arg}, $class);
223 }
224 else {
225 2 ▶ Carp::croak("Not sure what to do with '$type' in $class constructor")
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "ARRAY" 0 2 2
226 unless $type eq 'ARRAY';
227  
228 2 my %proto;
229 2 my @attributes = attr_list($class);
230 2 ▶ while (@$arg) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$arg) 9 1 10
231 9 my $val = shift @$arg;
232 9 ▶ my $key = shift @attributes or Carp::croak("Too many arguments for $class constructor");
Branch: 1 branch
BranchTrueFalseTotal
my $key = shift @attributes or Carp::croak("Too many arguments for $class constructor") 1 8 9
233 8 $proto{$key} = $val;
234 }
235  
236 1 $self = bless(\%proto, $class);
237 }
238 }
239 else {
240 27 $self = bless({@_}, $class);
241 }
242  
243 $Getopt::Yath::HashBase::CAN_CACHE{$class} = $self->can('init')
244 29 ▶ unless exists $Getopt::Yath::HashBase::CAN_CACHE{$class};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Getopt::Yath::HashBase::CAN_CACHE{$class} 16 13 29
245  
246 29 $self->$_() for $_pre_init->();
247 29 ▶ $self->init() if $Getopt::Yath::HashBase::CAN_CACHE{$class};
Branch: 1 branch
BranchTrueFalseTotal
if $Getopt::Yath::HashBase::CAN_CACHE{$class} 21 8 29
248 28 $self->$_() for reverse $_post_init->();
249  
250 28 $self;
251 20 };
252  
253 20 ▶ my $new_lookup = $Getopt::Yath::HashBase::NEW_LOOKUP //= {};
Condition100%2/2
$Getopt::Yath::HashBase::NEW_LOOKUP //= {}
l!l
182
MC/DC100%1/1
$Getopt::Yath::HashBase::NEW_LOOKUP //= {}
$Getopt::Yath::HashBase::NEW_LOOKUP
Truth table100%2/2
A
A= $Getopt::Yath::HashBase::NEW_LOOKUP
Aresult
11
00
254 20 $new_lookup->{$new} = 1;
255  
256 20 my %out;
257  
258 {
259 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
260 20 ▶ $out{new} = $new unless defined(&{"${into}\::new"});
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{"${into}::new";} 20 0 20
261 20 ▶ $out{add_pre_init} = $add_pre_init unless defined(&{"${into}\::add_pre_init"});
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{"${into}::add_pre_init";} 20 0 20
262 20 ▶ $out{add_post_init} = $add_post_init unless defined(&{"${into}\::add_post_init"});
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{"${into}::add_post_init";} 20 0 20
263 20 ▶ $out{_pre_init} = $_pre_init unless defined(&{"${into}\::_pre_init"});
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{"${into}::_pre_init";} 20 0 20
264 20 ▶ $out{_post_init} = $_post_init unless defined(&{"${into}\::_post_init"});
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{"${into}::_post_init";} 20 0 20
265 }
266  
267 20 return %out;
268 }
269  
270 2 1;
271  
272 __END__
« Yath/Term.pm ↑ Summary Yath/Settings/Group.pm »