/tmp/PTXakrS_Xp/lib/My/Prefix/HashBase.pm

filter: Statementstmt 49.4% 129 / 261 Branchbran 30.3% 37 / 122 Conditioncond 30.0% 12 / 40 MC/DCmcdc 8.7% 2 / 23 Subroutinesub 51.6% 16 / 31 Podpod 25.0% 1 / 4 totaltotal 40.9% 197 / 481 CC 90 SCAR 51.7
CC
90
Cov
42%
do_import
445.4
__ANON__
110.0
attr_list
72.0
CRAP 175.2
↑ Summary blib/lib/Object/HashBase.pm »
1 package My::Prefix::HashBase;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '123';
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 1 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 $My::Prefix::HashBase::HB_VERSION = '0.017';
20 1 *My::Prefix::HashBase::ATTR_SUBS = \%Object::HashBase::ATTR_SUBS;
21 1 *My::Prefix::HashBase::ATTR_LIST = \%Object::HashBase::ATTR_LIST;
22 1 *My::Prefix::HashBase::VERSION = \%Object::HashBase::VERSION;
23 1 *My::Prefix::HashBase::CAN_CACHE = \%Object::HashBase::CAN_CACHE;
24 }
25  
26  
27 1 require Carp;
28 {
29 1 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 $Carp::Internal{+__PACKAGE__} = 1;
31 }
32  
33 BEGIN {
34 {
35 # Make sure none of these get messed up.
36 1 ▶ local ($SIG{__DIE__}, $@, $?, $!, $^E);
Subroutine BEGIN: called CC=4 SCAR=16.8
37 1 ▶ 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 } }) { } 1 0 1
38 *CLASS_XS_ACCESSOR = sub() { 1 }
39 1 }
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 1 ▶ 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 1 ▶}
Branch: 1 branch
BranchTrueFalseTotal
$] >= 5.01 && require mro ? : 1 0 1
Condition33%1/3
$] >= "5.01" and require mro
!ll&&!rl&&r
001
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 sub _is_role {
59 2 ▶ my $pkg = shift;
Subroutine _is_role: called CC=3 SCAR=15.4
60 2 ▶ return 0 unless $INC{'Role/Tiny.pm'};
Branch: 1 branch
BranchTrueFalseTotal
unless $INC{"Role/Tiny.pm"} 2 0 2
61 0 ▶ return Role::Tiny->is_role($pkg) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
'Role::Tiny'->is_role($pkg) ? : 0 0 0
62 }
63  
64 1 my %SPEC = (
65 '^' => {reader => 1, writer => 0, dep_writer => 1, read_only => 0, strip => 1},
66 '-' => {reader => 1, writer => 0, dep_writer => 0, read_only => 1, strip => 1},
67 '>' => {reader => 0, writer => 1, dep_writer => 0, read_only => 0, strip => 1},
68 '<' => {reader => 1, writer => 0, dep_writer => 0, read_only => 0, strip => 1},
69 '+' => {reader => 0, writer => 0, dep_writer => 0, read_only => 0, strip => 1},
70 '~' => {reader => 1, writer => 1, dep_writer => 0, read_only => 0, strip => 1, no_xs => 1},
71 );
72  
73 2 ▶sub spec { \%SPEC }
Subroutine spec: called CC=1 SCAR=0.0
Pod undocumented
74  
75 sub import {
76 2 ▶ my $class = shift;
Subroutine import: called CC=1 SCAR=0.0
77 2 my $into = caller;
78 2 $class->do_import($into, @_);
79 }
80  
81 sub do_import {
82 2 ▶ my $class = shift;
Subroutine do_import: called CC=41 SCAR=61.0
Pod undocumented
83 2 my $into = shift;
84  
85 # Make sure we list the OLDEST version used to create this class.
86 2 ▶ my $ver = $My::Prefix::HashBase::HB_VERSION || $My::Prefix::HashBase::VERSION;
Condition33%1/3
$HB_VERSION || $VERSION
l!l&&r!l&&!r
200
MC/DC0%0/2
$HB_VERSION || $VERSION
$HB_VERSION $VERSION
Truth table33%1/3
A || B
A= $HB_VERSIONB= $VERSION
ABresult
1X1
011
000
87 2 ▶ $My::Prefix::HashBase::VERSION{$into} = $ver if !$My::Prefix::HashBase::VERSION{$into} || $My::Prefix::HashBase::VERSION{$into} > $ver;
Branch: 1 branch
BranchTrueFalseTotal
if not $My::Prefix::HashBase::VERSION{$into} or $My::Prefix::HashBase::VERSION{$into} > $ver 2 0 2
Condition33%1/3
not $My::Prefix::HashBase::VERSION{$into} or $My::Prefix::HashBase::VERSION{$into} > $ver
l!l&&r!l&&!r
200
MC/DC0%0/2
not $My::Prefix::HashBase::VERSION{$into} or $My::Prefix::HashBase::VERSION{$into} > $ver
not $My::Prefix::HashBase::VERSION{$into} $My::Prefix::HashBase::VERSION{$into} > $ver
Truth table33%1/3
not(A) or B
A= not $My::Prefix::HashBase::VERSION{$into}B= $My::Prefix::HashBase::VERSION{$into} > $ver
ABresult
1X1
011
000
88  
89 2 my (@parents, @roles, @attrs);
90 2 for my $arg (@_) {
91 2 ▶ if (defined($arg) && length($arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg and length $arg) 2 0 2
Condition33%1/3
defined $arg and length $arg
!ll&&!rl&&r
002
MC/DC0%0/2
defined $arg and length $arg
defined $arg length $arg
Truth table33%1/3
A and B
A= defined $argB= length $arg
ABresult
0X0
100
111
92 2 my $p = substr($arg, 0, 1);
93 2 ▶ if ($p eq '@') {
Branch: 1 branch
BranchTrueFalseTotal
if ($p eq "\@") 0 2 2
94 0 push @parents, substr($arg, 1);
95 0 next;
96 }
97 2 ▶ if ($p eq '&') {
Branch: 1 branch
BranchTrueFalseTotal
if ($p eq "&") 0 2 2
98 0 push @roles, substr($arg, 1);
99 0 next;
100 }
101 }
102 2 push @attrs, $arg;
103 }
104  
105 2 for my $parent (@parents) {
106 0 my $pm = $parent;
107 0 $pm =~ s{::}{/}g;
108 0 $pm .= '.pm';
109 0 ▶ unless ($INC{$pm}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($INC{$pm}) 0 0 0
110 0 local ($@);
111 0 ▶ unless (eval { require $pm; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require $pm; 1 } }) 0 0 0
112 0 Carp::croak("Could not load parent class '$parent': $@");
113 }
114 }
115 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
116 0 ▶ push @{"$into\::ISA"}, $parent unless grep { $_ eq $parent } @{"$into\::ISA"};
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $parent;} @{"${into}::ISA";} 0 0 0
117 }
118  
119 2 my $isa = _isa($into);
120 2 ▶ my $attr_list = $My::Prefix::HashBase::ATTR_LIST{$into} ||= [];
Condition50%1/2
$My::Prefix::HashBase::ATTR_LIST{$into} ||= []
l!l
02
MC/DC0%0/1
$My::Prefix::HashBase::ATTR_LIST{$into} ||= []
$My::Prefix::HashBase::ATTR_LIST{$into}
Truth table50%1/2
A
A= $My::Prefix::HashBase::ATTR_LIST{$into}
Aresult
11
00
121 2 ▶ my $attr_subs = $My::Prefix::HashBase::ATTR_SUBS{$into} ||= {};
Condition50%1/2
$My::Prefix::HashBase::ATTR_SUBS{$into} ||= {}
l!l
02
MC/DC0%0/1
$My::Prefix::HashBase::ATTR_SUBS{$into} ||= {}
$My::Prefix::HashBase::ATTR_SUBS{$into}
Truth table50%1/2
A
A= $My::Prefix::HashBase::ATTR_SUBS{$into}
Aresult
11
00
122  
123 2 my @pre_init;
124 my @post_init;
125  
126 2 ▶ my $add_new = _is_role($into) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
_is_role($into) ? : 0 2 2
127  
128 2 ▶ if ($add_new && (my $have_new = $into->can('new'))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add_new and my $have_new = $into->can("new")) 1 1 2
Condition66%2/3
$add_new and my $have_new = $into->can("new")
!ll&&!rl&&r
011
MC/DC50%1/2
$add_new and my $have_new = $into->can("new")
$add_new my $have_new = $into->can("new")
Truth table66%2/3
A and B
A= $add_newB= my $have_new = $into->can("new")
ABresult
0X0
100
111
129 1 ▶ my $new_lookup = $My::Prefix::HashBase::NEW_LOOKUP //= {};
Condition50%1/2
$My::Prefix::HashBase::NEW_LOOKUP //= {}
l!l
10
MC/DC0%0/1
$My::Prefix::HashBase::NEW_LOOKUP //= {}
$My::Prefix::HashBase::NEW_LOOKUP
Truth table50%1/2
A
A= $My::Prefix::HashBase::NEW_LOOKUP
Aresult
11
00
130 1 ▶ $add_new = 0 unless $new_lookup->{$have_new};
Branch: 1 branch
BranchTrueFalseTotal
unless $new_lookup->{$have_new} 0 1 1
131 }
132  
133 my %subs = (
134 ($add_new ? ($class->_build_new($into, \@pre_init, \@post_init)) : ()),
135 2 ▶ (map %{$My::Prefix::HashBase::ATTR_SUBS{$_} || {}}, @{$isa}[1 .. $#$isa]),
Branch: 2 branches
BranchTrueFalseTotal
$add_new ? : 2 0 2
$My::Prefix::HashBase::ATTR_SUBS{$_} or {} 0 1 1
136 ($class->args_to_subs($attr_list, $attr_subs, \@attrs, $into)),
137 );
138  
139 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
140 2 ▶ while (my ($k, $v) = each %subs) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %subs) 17 2 19
141 17 ▶ if (ref($v) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq 'CODE') { } 13 4 17
142 13 *{"$into\::$k"} = $v;
143 }
144 else {
145 4 my ($sub, @args) = @$v;
146 4 $sub->(@args);
147 }
148 }
149  
150 2 ▶ if (@roles) {
Branch: 1 branch
BranchTrueFalseTotal
if (@roles) 0 2 2
151 0 ▶ Carp::croak("My::Prefix::HashBase '&' role prefix requires Perl 5.010 or newer (this is $])")
Branch: 1 branch
BranchTrueFalseTotal
if $] < "5.01" 0 0 0
152 if $] < 5.010;
153  
154 0 ▶ unless ($INC{'Role/Tiny.pm'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($INC{"Role/Tiny.pm"}) 0 0 0
155 0 local ($@);
156 0 ▶ unless (eval { require Role::Tiny; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require Role::Tiny; 1 } }) 0 0 0
157 0 Carp::croak("My::Prefix::HashBase '&' role prefix requires Role::Tiny but it could not be loaded: $@");
158 }
159 }
160  
161 0 ▶ unless (Role::Tiny->can('is_role')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("Role::Tiny"->can("is_role")) 0 0 0
162 0 Carp::croak("My::Prefix::HashBase '&' role prefix requires Role::Tiny 1.003000 or newer (is_role missing)");
163 }
164  
165 0 for my $role (@roles) {
166 0 my $pm = $role;
167 0 $pm =~ s{::}{/}g;
168 0 $pm .= '.pm';
169  
170 0 ▶ unless ($INC{$pm}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($INC{$pm}) 0 0 0
171 0 local ($@);
172 0 ▶ unless (eval { require $pm; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require $pm; 1 } }) 0 0 0
173 0 Carp::croak("Could not load role '$role': $@");
174 }
175 }
176  
177 0 ▶ Carp::croak("'$role' is not a Role::Tiny role")
Branch: 1 branch
BranchTrueFalseTotal
unless "Role::Tiny"->is_role($role) 0 0 0
178 unless Role::Tiny->is_role($role);
179  
180 Carp::croak("'$role' does not use My::Prefix::HashBase")
181 0 ▶ unless exists $My::Prefix::HashBase::VERSION{$role};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $My::Prefix::HashBase::VERSION{$role} 0 0 0
182  
183 0 ▶ my $role_subs = $My::Prefix::HashBase::ATTR_SUBS{$role} || {};
Condition0%0/2
$My::Prefix::HashBase::ATTR_SUBS{$role} || {}
l!l
00
MC/DC0%0/1
$My::Prefix::HashBase::ATTR_SUBS{$role} || {}
$My::Prefix::HashBase::ATTR_SUBS{$role}
Truth table0%0/2
A
A= $My::Prefix::HashBase::ATTR_SUBS{$role}
Aresult
11
00
184  
185 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
186 0 for my $const (keys %$role_subs) {
187 0 ▶ next if defined &{"$into\::$const"}; # keep existing sub, no override, no warn
Branch: 1 branch
BranchTrueFalseTotal
if defined &{"${into}::$const";} 0 0 0
188 0 *{"$into\::$const"} = $role_subs->{$const};
189 }
190  
191 0 ▶ my $role_attr_list = $My::Prefix::HashBase::ATTR_LIST{$role} || [];
Condition0%0/2
$My::Prefix::HashBase::ATTR_LIST{$role} || []
l!l
00
MC/DC0%0/1
$My::Prefix::HashBase::ATTR_LIST{$role} || []
$My::Prefix::HashBase::ATTR_LIST{$role}
Truth table0%0/2
A
A= $My::Prefix::HashBase::ATTR_LIST{$role}
Aresult
11
00
192 0 ▶ push @{$My::Prefix::HashBase::ROLE_ATTRS{$into} ||= []}, @$role_attr_list;
Condition0%0/2
$My::Prefix::HashBase::ROLE_ATTRS{$into} ||= []
l!l
00
MC/DC0%0/1
$My::Prefix::HashBase::ROLE_ATTRS{$into} ||= []
$My::Prefix::HashBase::ROLE_ATTRS{$into}
Truth table0%0/2
A
A= $My::Prefix::HashBase::ROLE_ATTRS{$into}
Aresult
11
00
193 }
194  
195 0 my $key = "My::Prefix::HashBase::role_applier::$into";
196 0 ▶ my $applier = $^H{$key} ||= My::Prefix::HashBase::_RoleApplier->new($into);
Condition0%0/3
$^H{$key} ||= "My::Prefix::HashBase::_RoleApplier"->new($into)
l!l&&r!l&&!r
000
MC/DC0%0/2
$^H{$key} ||= "My::Prefix::HashBase::_RoleApplier"->new($into)
$^H{$key} "My::Prefix::HashBase::_RoleApplier"->new($into)
Truth table0%0/3
A ||= B
A= $^H{$key}B= "My::Prefix::HashBase::_RoleApplier"->new($into)
ABresult
1X1
011
000
197 0 $applier->add($_) for @roles;
198 }
199 }
200  
201 sub args_to_subs {
202 2 ▶ my $class = shift;
Subroutine args_to_subs: called CC=16 SCAR=38.1
Pod undocumented
203 2 my ($attr_list, $attr_subs, $args, $into) = @_;
204  
205 2 my $use_gen = $class->can('gen_accessor') ;
206  
207 2 my %out;
208  
209 2 ▶ while (@$args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$args) 2 2 4
210 2 my $x = shift @$args;
211 2 my $p = substr($x, 0, 1);
212  
213 2 ▶ my $spec = $class->spec->{$p} || {reader => 1, writer => 1};
Condition50%1/2
$class->spec->{$p} || {'reader', 1, 'writer', 1}
l!l
02
MC/DC0%0/1
$class->spec->{$p} || {'reader', 1, 'writer', 1}
$class->spec->{$p}
Truth table50%1/2
A
A= $class->spec->{$p}
Aresult
11
00
214 2 ▶ substr($x, 0, 1) = '' if $spec->{strip};
Branch: 1 branch
BranchTrueFalseTotal
if $spec->{"strip"} 0 2 2
215  
216 2 push @$attr_list => $x;
217 2 my ($sub, $attr) = (uc $x, $x);
218  
219 2 ▶ $attr_subs->{$sub} = sub() { $attr };
Subroutine __ANON__: not called CC=1 SCAR=1.2
220 2 $out{$sub} = $attr_subs->{$sub};
221  
222 2 my $copy = "$attr";
223 2 ▶ if ($spec->{reader}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{"reader"}) 2 0 2
224 2 ▶ if ($use_gen) {
Branch: 2 branches
BranchTrueFalseTotal
if ($use_gen) { } 0 2 2
elsif (not $spec->{'no_xs'}) { } 2 0 2
225 0 $out{$attr} = $class->gen_accessor(reader => $copy, $spec, $args);
226 }
227 elsif (CLASS_XS_ACCESSOR && !$spec->{no_xs}) {
228 2 $out{$attr} = [\&Class::XSAccessor::newxs_getter, "$into\::$attr", $copy];
229 }
230 else {
231 0 ▶ $out{$attr} = sub { $_[0]->{$attr} };
Subroutine __ANON__: not called CC=1 SCAR=6.9
232 }
233 }
234  
235 2 ▶ if ($spec->{writer}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($spec->{'writer'}) { } 2 0 2
elsif ($spec->{'read_only'}) { } 0 0 0
elsif ($spec->{'dep_writer'}) { } 0 0 0
236 2 ▶ if ($use_gen) {
Branch: 2 branches
BranchTrueFalseTotal
if ($use_gen) { } 0 2 2
elsif (not $spec->{'no_xs'}) { } 2 0 2
237 0 $out{"set_$attr"} = $class->gen_accessor(writer => $copy, $spec, $args);
238 }
239 elsif(CLASS_XS_ACCESSOR && !$spec->{no_xs}) {
240 2 $out{"set_$attr"} = [\&Class::XSAccessor::newxs_setter, "$into\::set_$attr", $copy, 0];
241 }
242 else {
243 0 ▶ $out{"set_$attr"} = sub { $_[0]->{$attr} = $_[1] };
Subroutine __ANON__: not called CC=1 SCAR=6.9
244 }
245 }
246 elsif($spec->{read_only}) {
247 0 ▶ $out{"set_$attr"} = $use_gen ? $class->gen_accessor(read_only => $copy, $spec, $args) : sub { Carp::croak("'$attr' is read-only") };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$use_gen ? : 0 0 0
248 }
249 elsif($spec->{dep_writer}) {
250 0 ▶ $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__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$use_gen ? : 0 0 0
251 }
252  
253 2 ▶ if ($spec->{custom}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{"custom"}) 0 2 2
254 0 my %add = $class->gen_accessor(custom => $copy, $spec, $args);
255 0 $out{$_} = $add{$_} for keys %add;
256 }
257 }
258  
259 2 return %out;
260 }
261  
262 sub attr_list {
263 0 ▶ my $class = shift;
Subroutine attr_list: not called CC=8 SCAR=42.8
Pod documented
264  
265 0 my $isa = _isa($class);
266  
267 0 my %seen;
268 my @list;
269 0 for my $pkg (reverse @$isa) {
270 0 ▶ if (0.004 > ($My::Prefix::HashBase::VERSION{$pkg} || 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ("0.004" > ($My::Prefix::HashBase::VERSION{$pkg} || 0)) 0 0 0
Condition0%0/2
$My::Prefix::HashBase::VERSION{$pkg} || 0
l!l
00
MC/DC0%0/1
$My::Prefix::HashBase::VERSION{$pkg} || 0
$My::Prefix::HashBase::VERSION{$pkg}
Truth table0%0/2
A
A= $My::Prefix::HashBase::VERSION{$pkg}
Aresult
11
00
271 0 Carp::carp("$pkg uses an inlined version of My::Prefix::HashBase too old to support attr_list()");
272 0 next;
273 }
274 0 my $own = $My::Prefix::HashBase::ATTR_LIST{$pkg};
275 0 ▶ my $role_attrs = $My::Prefix::HashBase::ROLE_ATTRS{$pkg} || [];
Condition0%0/2
$My::Prefix::HashBase::ROLE_ATTRS{$pkg} || []
l!l
00
MC/DC0%0/1
$My::Prefix::HashBase::ROLE_ATTRS{$pkg} || []
$My::Prefix::HashBase::ROLE_ATTRS{$pkg}
Truth table0%0/2
A
A= $My::Prefix::HashBase::ROLE_ATTRS{$pkg}
Aresult
11
00
276 0 ▶ for my $a (@$role_attrs, ($own ? @$own : ())) {
Branch: 1 branch
BranchTrueFalseTotal
$own ? : 0 0 0
277 0 ▶ push @list, $a unless $seen{$a}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $seen{$a}++ 0 0 0
278 }
279 }
280  
281 0 return @list;
282 }
283  
284 sub _build_new {
285 2 ▶ my $class = shift;
Subroutine _build_new: called CC=9 SCAR=31.0
286 2 my ($into, $pre_init, $post_init) = @_;
287  
288 2 ▶ my $add_pre_init = sub(&) { push @$pre_init => $_[-1] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
289 2 ▶ my $add_post_init = sub(&) { push @$post_init => $_[-1] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
290  
291 2 my $__pre_init = $into->can('_pre_init');
292 2 ▶ my $_pre_init = $__pre_init ? sub { ($__pre_init->(), @$pre_init) } : sub { @$pre_init };
Subroutine __ANON__: not called CC=1 SCAR=0.6
Branch: 1 branch
BranchTrueFalseTotal
$__pre_init ? : 1 1 2
293  
294 2 my $__post_init = $into->can('_post_init');
295 2 ▶ my $_post_init = $__post_init ? sub { ($__post_init->(), @$post_init) } : sub { @$post_init };
Subroutine __ANON__: not called CC=1 SCAR=0.6
Branch: 1 branch
BranchTrueFalseTotal
$__post_init ? : 1 1 2
296  
297 my $new = sub {
298 0 ▶ my $class = shift;
Subroutine __ANON__: not called CC=10 SCAR=47.0
299  
300 0 my $self;
301  
302 0 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
303 0 my $arg = shift;
304 0 my $type = ref($arg);
305  
306 0 ▶ if ($type eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'HASH') { } 0 0 0
307 0 $self = bless({%$arg}, $class);
308 }
309 else {
310 0 ▶ Carp::croak("Not sure what to do with '$type' in $class constructor")
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "ARRAY" 0 0 0
311 unless $type eq 'ARRAY';
312  
313 0 my %proto;
314 0 my @attributes = attr_list($class);
315 0 ▶ while (@$arg) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$arg) 0 0 0
316 0 my $val = shift @$arg;
317 0 ▶ 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") 0 0 0
318 0 $proto{$key} = $val;
319 }
320  
321 0 $self = bless(\%proto, $class);
322 }
323 }
324 else {
325 0 $self = bless({@_}, $class);
326 }
327  
328 $My::Prefix::HashBase::CAN_CACHE{$class} = $self->can('init')
329 0 ▶ unless exists $My::Prefix::HashBase::CAN_CACHE{$class};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $My::Prefix::HashBase::CAN_CACHE{$class} 0 0 0
330  
331 0 $self->$_() for $_pre_init->();
332 0 ▶ $self->init() if $My::Prefix::HashBase::CAN_CACHE{$class};
Branch: 1 branch
BranchTrueFalseTotal
if $My::Prefix::HashBase::CAN_CACHE{$class} 0 0 0
333 0 $self->$_() for reverse $_post_init->();
334  
335 0 $self;
336 2 };
337  
338 2 ▶ my $new_lookup = $My::Prefix::HashBase::NEW_LOOKUP //= {};
Condition100%2/2
$My::Prefix::HashBase::NEW_LOOKUP //= {}
l!l
11
MC/DC100%1/1
$My::Prefix::HashBase::NEW_LOOKUP //= {}
$My::Prefix::HashBase::NEW_LOOKUP
Truth table100%2/2
A
A= $My::Prefix::HashBase::NEW_LOOKUP
Aresult
11
00
339 2 $new_lookup->{$new} = 1;
340  
341 2 my %out;
342  
343 {
344 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
345 2 ▶ $out{new} = $new unless defined(&{"${into}\::new"});
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{"${into}::new";} 2 0 2
346 2 ▶ $out{add_pre_init} = $add_pre_init unless defined(&{"${into}\::add_pre_init"});
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{"${into}::add_pre_init";} 2 0 2
347 2 ▶ $out{add_post_init} = $add_post_init unless defined(&{"${into}\::add_post_init"});
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{"${into}::add_post_init";} 2 0 2
348 2 ▶ $out{_pre_init} = $_pre_init unless defined(&{"${into}\::_pre_init"});
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{"${into}::_pre_init";} 2 0 2
349 2 ▶ $out{_post_init} = $_post_init unless defined(&{"${into}\::_post_init"});
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{"${into}::_post_init";} 2 0 2
350 }
351  
352 2 return %out;
353 }
354  
355 # _RoleApplier — deferred Role::Tiny composition.
356 #
357 # My::Prefix::HashBase's '&' import prefix copies role constants into the consumer
358 # eagerly (so `$self->{+FOO}` resolves at compile time), then defers actual
359 # Role::Tiny->apply_roles_to_package to end of consumer's compile scope by
360 # storing a blessed object in %^H. Perl destroys %^H entries at end of compile
361 # scope, triggering DESTROY here, which finally composes the role(s).
362  
363 package # hide from PAUSE indexer
364 My::Prefix::HashBase::_RoleApplier;
365  
366 sub new {
367 0 ▶ my ($class, $into) = @_;
Subroutine new: not called CC=1 SCAR=6.9
368 0 return bless { into => $into, roles => [] }, $class;
369 }
370  
371 sub add {
372 0 ▶ my ($self, $role) = @_;
Subroutine add: not called CC=2 SCAR=17.9
373 0 push @{$self->{roles}}, $role
374 0 ▶ unless grep { $_ eq $role } @{$self->{roles}};
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $role;} @{$$self{"roles"};} 0 0 0
375 }
376  
377 sub DESTROY {
378 0 ▶ my $self = shift;
Subroutine DESTROY: not called CC=4 SCAR=30.0
379 0 ▶ return unless @{$self->{roles}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"roles"};} 0 0 0
380 0 local $@;
381 0 my $ok = eval { Role::Tiny->apply_roles_to_package($self->{into}, @{$self->{roles}}); 1 };
382 0 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
383 0 ▶ my $err = $@ || 'unknown error';
Condition0%0/2
$@ || 'unknown error'
l!l
00
MC/DC0%0/1
$@ || 'unknown error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
384 0 my $into = $self->{into};
385 0 my $roles = join(', ', @{$self->{roles}});
386 0 warn "My::Prefix::HashBase: failed to compose role(s) [$roles] into $into: $err";
387 }
388 }
389  
390 1 1;
391  
392 __END__
↑ Summary blib/lib/Object/HashBase.pm »