blib/lib/Moo/Role.pm

filter: Statementstmt 97.4% 231 / 237 Branchbran 92.1% 70 / 76 Conditioncond 80.3% 98 / 122 MC/DCmcdc 59.3% 38 / 64 Subroutinesub 95.1% 39 / 41 Podpod 60.0% 3 / 5 totaltotal 87.8% 479 / 545 CC 93 SCAR 19.9
CC
93
Cov
92%
_inhale_if_moose
19.1
_handle_constructor
13.0
_make_accessors_if_moose
12.0
CRAP 7.3
« blib/lib/Moo/HandleMoose/_TypeMap.pm ↑ Summary blib/lib/Moo/_Utils.pm »
1 package Moo::Role;
2 63 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 63 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 63 ▶use Moo::_Utils qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
6 _check_tracked
7 _getglob
8 _getstash
9 _install_coderef
10 _install_modifier
11 _install_tracked
12 _load_module
13 _name_coderef
14 _set_loaded
15 _unimport_coderefs
16 63 );
17 63 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 63 ▶use Role::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 63 ▶BEGIN { our @ISA = qw(Role::Tiny) }
Subroutine BEGIN: called CC=1 SCAR=0.0
20 63 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
21 63 our @CARP_NOT = qw(
22 Method::Generate::Accessor
23 Method::Generate::Constructor
24 Moo::sification
25 Moo::_Utils
26 Role::Tiny
27 );
28 }
29  
30 63 our $VERSION = '2.005005';
31 63 $VERSION =~ tr/_//d;
32  
33 63 require Moo::sification;
34 63 Moo::sification->import;
35  
36 63 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
37 63 *INFO = \%Role::Tiny::INFO;
38 63 *APPLIED_TO = \%Role::Tiny::APPLIED_TO;
39 63 *COMPOSED = \%Role::Tiny::COMPOSED;
40 63 *ON_ROLE_CREATE = \@Role::Tiny::ON_ROLE_CREATE;
41 }
42  
43 63 our %INFO;
44 63 our %APPLIED_TO;
45 63 our %APPLY_DEFAULTS;
46 63 our %COMPOSED;
47 63 our @ON_ROLE_CREATE;
48  
49 96 ▶sub import {
Subroutine import: called CC=3 SCAR=11.0
50 96 my $target = caller;
51 96 ▶ if ($Moo::MAKERS{$target} and $Moo::MAKERS{$target}{is_class}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Moo::MAKERS{$target} and $Moo::MAKERS{$target}{"is_class"}) 2 94 96
Condition100%3/3
$Moo::MAKERS{$target} and $Moo::MAKERS{$target}{"is_class"}
!ll&&!rl&&r
9312
MC/DC100%2/2
$Moo::MAKERS{$target} and $Moo::MAKERS{$target}{"is_class"}
$Moo::MAKERS{$target} $Moo::MAKERS{$target}{"is_class"}
Truth table100%3/3
A and B
A= $Moo::MAKERS{$target}B= $Moo::MAKERS{$target}{"is_class"}
ABresult
0X0
100
111
52 2 croak "Cannot import Moo::Role into a Moo class";
53 }
54 94 _set_loaded(caller);
55 94 goto &Role::Tiny::import;
56 }
57  
58 49 ▶sub _accessor_maker_for {
Subroutine _accessor_maker_for: called CC=2 SCAR=7.0
59 49 my ($class, $target) = @_;
60 49 ▶ ($INFO{$target}{accessor_maker} ||= do {
Condition66%2/3
$Moo::Role::INFO{$target}{"accessor_maker"} ||= do { require Method::Generate::Accessor; "Method::Generate::Accessor"->new }
l!l&&r!l&&!r
8410
MC/DC0%0/2
$Moo::Role::INFO{$target}{"accessor_maker"} ||= do { require Method::Generate::Accessor; "Method::Generate::Accessor"->new }
$Moo::Role::INFO{$target}{"accessor_maker"} do { require Method::Generate::Accessor; "Method::Generate::Accessor"->new }
Truth table66%2/3
A ||= B
A= $Moo::Role::INFO{$target}{"accessor_maker"}B= do { require Method::Generate::Accessor; "Method::Generate::Accessor"->new }
ABresult
1X1
011
000
61 41 require Method::Generate::Accessor;
62 41 Method::Generate::Accessor->new
63 });
64 }
65  
66 94 ▶sub _install_subs {
Subroutine _install_subs: called CC=2 SCAR=6.9
67 94 my ($me, $target) = @_;
68 94 my %install = $me->_gen_subs($target);
69 _install_tracked $target => $_ => $install{$_}
70 94 for sort keys %install;
71 94 *{_getglob("${target}::meta")} = $me->can('meta');
72 94 return;
73 }
74  
75 208 ▶sub _require_module {
Subroutine _require_module: called CC=1 SCAR=0.0
76 208 _load_module($_[1]);
77 }
78  
79 94 ▶sub _gen_subs {
Subroutine _gen_subs: called CC=1 SCAR=0.0
80 94 my ($me, $target) = @_;
81 return (
82 32 ▶ has => sub {
Subroutine has: called CC=6 SCAR=17.9
83 32 my $name_proto = shift;
84 32 ▶ my @name_proto = ref $name_proto eq 'ARRAY' ? @$name_proto : $name_proto;
Branch: 2 branches
BranchTrueFalseTotal
ref $name_proto eq 'ARRAY' ? : 0 32 32
ref $name_proto eq 'ARRAY' ? : 2 16 18
85 32 ▶ if (@_ % 2 != 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ % 2 != 0) 1 31 32
if (@_ % 2 != 0) 1 17 18
86 1 croak("Invalid options for " . join(', ', map "'$_'", @name_proto)
87 . " attribute(s): even number of arguments expected, got " . scalar @_)
88 }
89 31 my %spec = @_;
90 31 foreach my $name (@name_proto) {
91 31 ▶ my $spec_ref = @name_proto > 1 ? +{%spec} : \%spec;
Branch: 2 branches
BranchTrueFalseTotal
@name_proto > 1 ? : 0 31 31
@name_proto > 1 ? : 2 16 18
92 31 $me->_accessor_maker_for($target)
93 ->generate_method($target, $name, $spec_ref);
94 31 ▶ push @{$INFO{$target}{attributes}||=[]}, $name, $spec_ref;
Condition100%2/2
$Moo::Role::INFO{$target}{"attributes"} ||= []
l!l
229
MC/DC100%1/1
$Moo::Role::INFO{$target}{"attributes"} ||= []
$Moo::Role::INFO{$target}{"attributes"}
Truth table100%2/2
A
A= $Moo::Role::INFO{$target}{"attributes"}
Aresult
11
00
95 31 $me->_maybe_reset_handlemoose($target);
96 }
97 },
98 (map {
99 282 my $type = $_;
100 (
101 0 ▶ $type => sub {
Subroutine before: not called CC=2 SCAR=8.0
Subroutine after: called CC=2 SCAR=8.0
102 0 ▶ push @{$INFO{$target}{modifiers}||=[]}, [ $type => @_ ];
Condition50%2/4
$Moo::Role::INFO{$target}{"modifiers"} ||= []
l!l
00
$Moo::Role::INFO{$target}{"modifiers"} ||= []
l!l
819
MC/DC0%0/1
$Moo::Role::INFO{$target}{"modifiers"} ||= []
$Moo::Role::INFO{$target}{"modifiers"}
MC/DC100%1/1
$Moo::Role::INFO{$target}{"modifiers"} ||= []
$Moo::Role::INFO{$target}{"modifiers"}
Truth table0%0/2
A
A= $Moo::Role::INFO{$target}{"modifiers"}
Aresult
11
00
Truth table100%2/2
A
A= $Moo::Role::INFO{$target}{"modifiers"}
Aresult
11
00
103 0 $me->_maybe_reset_handlemoose($target);
104 },
105 )
106 282 } qw(before after around)),
107 1 ▶ requires => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
Subroutine requires: called CC=2 SCAR=7.0
108 1 ▶ push @{$INFO{$target}{requires}||=[]}, @_;
Condition75%3/4
$Moo::Role::INFO{$target}{"requires"} ||= []
l!l
01
$Moo::Role::INFO{$target}{"requires"} ||= []
l!l
210
MC/DC0%0/1
$Moo::Role::INFO{$target}{"requires"} ||= []
$Moo::Role::INFO{$target}{"requires"}
MC/DC100%1/1
$Moo::Role::INFO{$target}{"requires"} ||= []
$Moo::Role::INFO{$target}{"requires"}
Truth table50%1/2
A
A= $Moo::Role::INFO{$target}{"requires"}
Aresult
11
00
Truth table100%2/2
A
A= $Moo::Role::INFO{$target}{"requires"}
Aresult
11
00
109 1 $me->_maybe_reset_handlemoose($target);
110 },
111 7 ▶ with => sub {
Subroutine with: called CC=1 SCAR=0.0
112 7 $me->apply_roles_to_package($target, @_);
113 7 $me->_maybe_reset_handlemoose($target);
114 },
115 94 );
116 }
117  
118 95 ▶push @ON_ROLE_CREATE, sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
119 95 my $target = shift;
120 95 ▶ if ($INC{'Moo/HandleMoose.pm'} && !$Moo::sification::disabled) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Moo/HandleMoose.pm"} and not $Moo::sification::disabled) 14 81 95
Condition100%3/3
$INC{"Moo/HandleMoose.pm"} and not $Moo::sification::disabled
!ll&&!rl&&r
80114
MC/DC100%2/2
$INC{"Moo/HandleMoose.pm"} and not $Moo::sification::disabled
$INC{"Moo/HandleMoose.pm"} not $Moo::sification::disabled
Truth table100%3/3
A and not(B)
A= $INC{"Moo/HandleMoose.pm"}B= not $Moo::sification::disabled
ABresult
0X0
100
111
121 14 Moo::HandleMoose::inject_fake_metaclass_for($target);
122 }
123 63 };
124  
125 # duplicate from Moo::Object
126 1 ▶sub meta {
Subroutine meta: called CC=2 SCAR=7.6
Pod undocumented
127 1 require Moo::HandleMoose::FakeMetaClass;
128 1 ▶ my $class = ref($_[0])||$_[0];
Condition33%1/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
129 1 bless({ name => $class }, 'Moo::HandleMoose::FakeMetaClass');
130 }
131  
132 5 ▶sub unimport {
Subroutine unimport: called CC=1 SCAR=0.0
133 5 my $target = caller;
134 5 _unimport_coderefs($target);
135 }
136  
137 78 ▶sub _maybe_reset_handlemoose {
Subroutine _maybe_reset_handlemoose: called CC=3 SCAR=11.0
138 78 my ($class, $target) = @_;
139 78 ▶ if ($INC{'Moo/HandleMoose.pm'} && !$Moo::sification::disabled) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Moo/HandleMoose.pm"} and not $Moo::sification::disabled) 31 47 78
Condition100%3/3
$INC{"Moo/HandleMoose.pm"} and not $Moo::sification::disabled
!ll&&!rl&&r
46131
MC/DC100%2/2
$INC{"Moo/HandleMoose.pm"} and not $Moo::sification::disabled
$INC{"Moo/HandleMoose.pm"} not $Moo::sification::disabled
Truth table100%3/3
A and not(B)
A= $INC{"Moo/HandleMoose.pm"}B= not $Moo::sification::disabled
ABresult
0X0
100
111
140 31 Moo::HandleMoose::maybe_reinject_fake_metaclass_for($target);
141 }
142 }
143  
144 181 ▶sub _non_methods {
Subroutine _non_methods: called CC=2 SCAR=6.9
145 181 my $self = shift;
146 181 my ($role) = @_;
147  
148 181 my $non_methods = $self->SUPER::_non_methods(@_);
149  
150 181 my $all_subs = $self->_all_subs($role);
151 $non_methods->{$_} = $all_subs->{$_}
152 181 for _check_tracked($role, [ keys %$all_subs ]);
153  
154 181 return $non_methods;
155 }
156  
157 385 ▶sub is_role {
Subroutine is_role: called CC=1 SCAR=0.0
Pod documented
158 385 my ($self, $role) = @_;
159 385 $self->_inhale_if_moose($role);
160 385 $self->SUPER::is_role($role);
161 }
162  
163 385 ▶sub _inhale_if_moose {
Subroutine _inhale_if_moose: called CC=19 SCAR=29.5
164 385 my ($self, $role) = @_;
165 385 my $meta;
166 385 ▶ if (!$self->SUPER::is_role($role)
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->SUPER::is_role($role) and ($INC{"Moose.pm"} and $meta = Class::MOP::class_of($role) and ref $meta ne "Moo::HandleMoose::FakeMetaClass" and $meta->isa("Moose::Meta::Role")) or "Mouse::Util"->can("find_meta") and $meta = Mouse::Util::find_meta($role) and $meta->isa("Mouse::Meta::Role")) 14 371 385
Condition90%19/21
not $self->SUPER::is_role($role) and ($INC{"Moose.pm"} and $meta = Class::MOP::class_of($role) and ref $meta ne "Moo::HandleMoose::FakeMetaClass" and $meta->isa("Moose::Meta::Role")) or "Mouse::Util"->can("find_meta") and $meta = Mouse::Util::find_meta($role) and $meta->isa("Mouse::Meta::Role")
l!l&&r!l&&!r
104371
not $self->SUPER::is_role($role) and ($INC{"Moose.pm"} and $meta = Class::MOP::class_of($role) and ref $meta ne "Moo::HandleMoose::FakeMetaClass" and $meta->isa("Moose::Meta::Role"))
!ll&&!rl&&r
17220310
$INC{"Moose.pm"} and $meta = Class::MOP::class_of($role) and ref $meta ne "Moo::HandleMoose::FakeMetaClass" and $meta->isa("Moose::Meta::Role")
!ll&&!rl&&r
203010
$INC{"Moose.pm"} and $meta = Class::MOP::class_of($role) and ref $meta ne "Moo::HandleMoose::FakeMetaClass"
!ll&&!rl&&r
1822110
$INC{"Moose.pm"} and $meta = Class::MOP::class_of($role)
!ll&&!rl&&r
1671531
"Mouse::Util"->can("find_meta") and $meta = Mouse::Util::find_meta($role) and $meta->isa("Mouse::Meta::Role")
!ll&&!rl&&r
37104
"Mouse::Util"->can("find_meta") and $meta = Mouse::Util::find_meta($role)
!ll&&!rl&&r
360114
MC/DC75%6/8
not $self->SUPER::is_role($role) and ($INC{"Moose.pm"} and $meta = Class::MOP::class_of($role) and ref $meta ne "Moo::HandleMoose::FakeMetaClass" and $meta->isa("Moose::Meta::Role")) or "Mouse::Util"->can("find_meta") and $meta = Mouse::Util::find_meta($role) and $meta->isa("Mouse::Meta::Role")
not $self->SUPER::is_role($role) $INC{"Moose.pm"} $meta = Class::MOP::class_of($role) ref $meta ne "Moo::HandleMoose::FakeMetaClass" $meta->isa("Moose::Meta::Role") "Mouse::Util"->can("find_meta") $meta = Mouse::Util::find_meta($role) $meta->isa("Mouse::Meta::Role")
Truth table42%9/21
not(A) and B and C and D and E or F and G and H
A= not $self->SUPER::is_role($role)B= $INC{"Moose.pm"}C= $meta = Class::MOP::class_of($role)D= ref $meta ne "Moo::HandleMoose::FakeMetaClass"E= $meta->isa("Moose::Meta::Role")F= "Mouse::Util"->can("find_meta")G= $meta = Mouse::Util::find_meta($role)H= $meta->isa("Mouse::Meta::Role")
ABCDEFGHresult
11111XXX1
0XXXX1111
10XXX1111
110XX1111
1110X1111
111101111
0XXXX0XX0
0XXXX10X0
0XXXX1100
10XXX0XX0
10XXX10X0
10XXX1100
110XX0XX0
110XX10X0
110XX1100
1110X0XX0
1110X10X0
1110X1100
111100XX0
1111010X0
111101100
167 and (
168 $INC{"Moose.pm"}
169 and $meta = Class::MOP::class_of($role)
170 and ref $meta ne 'Moo::HandleMoose::FakeMetaClass'
171 and $meta->isa('Moose::Meta::Role')
172 )
173 or (
174 Mouse::Util->can('find_meta')
175 and $meta = Mouse::Util::find_meta($role)
176 and $meta->isa('Mouse::Meta::Role')
177 )
178 ) {
179 14 my $is_mouse = $meta->isa('Mouse::Meta::Role');
180 $INFO{$role}{methods} = {
181 14 ▶ map +($_ => $role->can($_)),
Condition100%3/3
$is_mouse && $_ eq 'meta'
!ll&&!rl&&r
494
MC/DC100%2/2
$is_mouse && $_ eq 'meta'
$is_mouse $_ eq 'meta'
Truth table100%3/3
A && B
A= $is_mouseB= $_ eq 'meta'
ABresult
0X0
100
111
182 grep $role->can($_),
183 grep !($is_mouse && $_ eq 'meta'),
184 grep !$meta->get_method($_)->isa('Class::MOP::Method::Meta'),
185 $meta->get_method_list
186 };
187 14 $APPLIED_TO{$role} = {
188 map +($_->name => 1), $meta->calculate_all_roles
189 };
190 14 $INFO{$role}{requires} = [ $meta->get_required_method_list ];
191 $INFO{$role}{attributes} = [
192 14 map +($_ => do {
193 11 my $attr = $meta->get_attribute($_);
194 11 ▶ my $spec = { %{ $is_mouse ? $attr : $attr->original_options } };
Branch: 1 branch
BranchTrueFalseTotal
$is_mouse ? : 4 7 11
195  
196 11 ▶ if ($spec->{isa}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{"isa"}) 4 7 11
197 4 require Sub::Quote;
198  
199 4 my $get_constraint = do {
200 4 ▶ my $pkg = $is_mouse
Branch: 1 branch
BranchTrueFalseTotal
$is_mouse ? : 1 3 4
201 ? 'Mouse::Util::TypeConstraints'
202 : 'Moose::Util::TypeConstraints';
203 4 _load_module($pkg);
204 4 $pkg->can('find_or_create_isa_type_constraint');
205 };
206  
207 4 my $tc = $get_constraint->($spec->{isa});
208 4 my $check = $tc->_compiled_type_constraint;
209 4 my $tc_var = '$_check_for_'.Sub::Quote::sanitize_identifier($tc->name);
210  
211 4 $spec->{isa} = Sub::Quote::quote_sub(
212 qq{
213 &${tc_var} or Carp::croak "Type constraint failed for \$_[0]"
214 },
215 { $tc_var => \$check },
216 {
217 package => $role,
218 },
219 );
220  
221 4 ▶ if ($spec->{coerce}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{"coerce"}) 2 2 4
222  
223 # Mouse has _compiled_type_coercion straight on the TC object
224 2 $spec->{coerce} = $tc->${\(
225 1 ▶ $tc->can('coercion')||sub { $_[0] }
Subroutine __ANON__: called CC=1 SCAR=0.0
226 2 ▶ )}->_compiled_type_coercion;
Condition66%2/3
$tc->can('coercion') || sub { $_[0]; }
l!l&&r!l&&!r
110
MC/DC0%0/2
$tc->can('coercion') || sub { $_[0]; }
$tc->can('coercion') sub { $_[0]; }
Truth table66%2/3
A || B
A= $tc->can('coercion')B= sub { $_[0]; }
ABresult
1X1
011
000
227 }
228 }
229 11 $spec;
230 }), $meta->get_attribute_list
231 ];
232 14 my $mods = $INFO{$role}{modifiers} = [];
233 14 foreach my $type (qw(before after around)) {
234 # Mouse pokes its own internals so we have to fall back to doing
235 # the same thing in the absence of the Moose API method
236 42 my $map = $meta->${\(
237 $meta->can("get_${type}_method_modifiers_map")
238 12 ▶ or sub { shift->{"${type}_method_modifiers"} }
Subroutine __ANON__: called CC=1 SCAR=0.0
239 42 ▶ )};
Condition66%2/3
$meta->can("get_${type}_method_modifiers_map") || sub { (shift())->{"${type}_method_modifiers"}; }
l!l&&r!l&&!r
30120
MC/DC0%0/2
$meta->can("get_${type}_method_modifiers_map") || sub { (shift())->{"${type}_method_modifiers"}; }
$meta->can("get_${type}_method_modifiers_map") sub { (shift())->{"${type}_method_modifiers"}; }
Truth table66%2/3
A || B
A= $meta->can("get_${type}_method_modifiers_map")B= sub { (shift())->{"${type}_method_modifiers"}; }
ABresult
1X1
011
000
240 42 foreach my $method (keys %$map) {
241 4 foreach my $mod (@{$map->{$method}}) {
242 4 push @$mods, [ $type => $method => $mod ];
243 }
244 }
245 }
246 14 $INFO{$role}{inhaled_from_moose} = 1;
247 14 $INFO{$role}{is_role} = 1;
248 }
249 }
250  
251 110 ▶sub _maybe_make_accessors {
Subroutine _maybe_make_accessors: called CC=6 SCAR=17.9
252 110 my ($self, $target, $role) = @_;
253 110 my $m;
254 110 ▶ if ($INFO{$role} && $INFO{$role}{inhaled_from_moose}
Branch: 1 branch
BranchTrueFalseTotal
if ($Moo::Role::INFO{$role} and $Moo::Role::INFO{$role}{"inhaled_from_moose"} or $INC{"Moo.pm"} and $m = "Moo"->_accessor_maker_for($target) and ref $m ne "Method::Generate::Accessor") 21 89 110
Condition91%11/12
$Moo::Role::INFO{$role} and $Moo::Role::INFO{$role}{"inhaled_from_moose"} or $INC{"Moo.pm"} and $m = "Moo"->_accessor_maker_for($target) and ref $m ne "Method::Generate::Accessor"
l!l&&r!l&&!r
16589
$Moo::Role::INFO{$role} and $Moo::Role::INFO{$role}{"inhaled_from_moose"}
!ll&&!rl&&r
09416
$INC{"Moo.pm"} and $m = "Moo"->_accessor_maker_for($target) and ref $m ne "Method::Generate::Accessor"
!ll&&!rl&&r
8815
$INC{"Moo.pm"} and $m = "Moo"->_accessor_maker_for($target)
!ll&&!rl&&r
2686
MC/DC80%4/5
$Moo::Role::INFO{$role} and $Moo::Role::INFO{$role}{"inhaled_from_moose"} or $INC{"Moo.pm"} and $m = "Moo"->_accessor_maker_for($target) and ref $m ne "Method::Generate::Accessor"
$Moo::Role::INFO{$role} $Moo::Role::INFO{$role}{"inhaled_from_moose"} $INC{"Moo.pm"} $m = "Moo"->_accessor_maker_for($target) ref $m ne "Method::Generate::Accessor"
Truth table55%5/9
A and B or C and D and E
A= $Moo::Role::INFO{$role}B= $Moo::Role::INFO{$role}{"inhaled_from_moose"}C= $INC{"Moo.pm"}D= $m = "Moo"->_accessor_maker_for($target)E= ref $m ne "Method::Generate::Accessor"
ABCDEresult
11XXX1
0X1111
101111
0X0XX0
0X10X0
0X1100
100XX0
1010X0
101100
255 or $INC{"Moo.pm"}
256 and $m = Moo->_accessor_maker_for($target)
257 and ref($m) ne 'Method::Generate::Accessor') {
258 21 $self->_make_accessors($target, $role);
259 }
260 }
261  
262 0 ▶sub _make_accessors_if_moose {
Subroutine _make_accessors_if_moose: not called CC=3 SCAR=24.8
263 0 my ($self, $target, $role) = @_;
264 0 ▶ if ($INFO{$role} && $INFO{$role}{inhaled_from_moose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Moo::Role::INFO{$role} and $Moo::Role::INFO{$role}{"inhaled_from_moose"}) 0 0 0
Condition0%0/3
$Moo::Role::INFO{$role} and $Moo::Role::INFO{$role}{"inhaled_from_moose"}
!ll&&!rl&&r
000
MC/DC0%0/2
$Moo::Role::INFO{$role} and $Moo::Role::INFO{$role}{"inhaled_from_moose"}
$Moo::Role::INFO{$role} $Moo::Role::INFO{$role}{"inhaled_from_moose"}
Truth table0%0/3
A and B
A= $Moo::Role::INFO{$role}B= $Moo::Role::INFO{$role}{"inhaled_from_moose"}
ABresult
0X0
100
111
265 0 $self->_make_accessors($target, $role);
266 }
267 }
268  
269 21 ▶sub _make_accessors {
Subroutine _make_accessors: called CC=5 SCAR=16.1
270 21 my ($self, $target, $role) = @_;
271 21 ▶ my $acc_gen = ($Moo::MAKERS{$target}{accessor} ||= do {
Condition66%2/3
$Moo::MAKERS{$target}{"accessor"} ||= do { require Method::Generate::Accessor; "Method::Generate::Accessor"->new }
l!l&&r!l&&!r
1830
MC/DC0%0/2
$Moo::MAKERS{$target}{"accessor"} ||= do { require Method::Generate::Accessor; "Method::Generate::Accessor"->new }
$Moo::MAKERS{$target}{"accessor"} do { require Method::Generate::Accessor; "Method::Generate::Accessor"->new }
Truth table66%2/3
A ||= B
A= $Moo::MAKERS{$target}{"accessor"}B= do { require Method::Generate::Accessor; "Method::Generate::Accessor"->new }
ABresult
1X1
011
000
272 3 require Method::Generate::Accessor;
273 3 Method::Generate::Accessor->new
274 });
275 21 my $con_gen = $Moo::MAKERS{$target}{constructor};
276 21 ▶ my @attrs = @{$INFO{$role}{attributes}||[]};
Condition100%2/2
$Moo::Role::INFO{$role}{'attributes'} || []
l!l
201
MC/DC100%1/1
$Moo::Role::INFO{$role}{'attributes'} || []
$Moo::Role::INFO{$role}{'attributes'}
Truth table100%2/2
A
A= $Moo::Role::INFO{$role}{'attributes'}
Aresult
11
00
277 21 ▶ while (my ($name, $spec) = splice @attrs, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@attrs, 0, 2)) 18 21 39
278 # needed to ensure we got an index for an arrayref based generator
279 18 ▶ if ($con_gen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($con_gen) 16 2 18
280 16 $spec = $con_gen->all_attribute_specs->{$name};
281 }
282 18 $acc_gen->generate_method($target, $name, $spec);
283 }
284 }
285  
286 110 ▶sub _undefer_subs {
Subroutine _undefer_subs: called CC=2 SCAR=6.9
287 110 my ($self, $target, $role) = @_;
288 110 ▶ if ($INC{'Sub/Defer.pm'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Sub/Defer.pm"}) 99 11 110
289 99 Sub::Defer::undefer_package($role);
290 }
291 }
292  
293 82 ▶sub role_application_steps {
Subroutine role_application_steps: called CC=1 SCAR=0.0
Pod undocumented
294 82 qw(_handle_constructor _undefer_subs _maybe_make_accessors),
295 $_[0]->SUPER::role_application_steps;
296 }
297  
298 21 ▶sub _build_class_with_roles {
Subroutine _build_class_with_roles: called CC=8 SCAR=21.0
299 21 my ($me, $new_name, $superclass, @roles) = @_;
300 21 $Moo::MAKERS{$new_name} = {is_class => 1};
301 21 $me->SUPER::_build_class_with_roles($new_name, $superclass, @roles);
302  
303 20 ▶ if ($INC{'Moo/HandleMoose.pm'} && !$Moo::sification::disabled) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Moo/HandleMoose.pm"} and not $Moo::sification::disabled) 2 18 20
Condition100%3/3
$INC{"Moo/HandleMoose.pm"} and not $Moo::sification::disabled
!ll&&!rl&&r
1712
MC/DC100%2/2
$INC{"Moo/HandleMoose.pm"} and not $Moo::sification::disabled
$INC{"Moo/HandleMoose.pm"} not $Moo::sification::disabled
Truth table100%3/3
A and not(B)
A= $INC{"Moo/HandleMoose.pm"}B= not $Moo::sification::disabled
ABresult
0X0
100
111
304 2 Moo::HandleMoose::inject_fake_metaclass_for($new_name);
305 }
306  
307 20 my $lvl = 0;
308 20 my $file;
309 20 ▶ while ((my $pack, $file) = caller($lvl++)) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $pack, $file) = caller $lvl++) 56 0 56
310 56 ▶ if ($pack ne __PACKAGE__ && $pack ne 'Role::Tiny' && !$pack->isa($me)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pack ne __PACKAGE__ and $pack ne "Role::Tiny" and not $pack->isa($me)) 20 36 56
Condition83%5/6
$pack ne __PACKAGE__ and $pack ne "Role::Tiny" and not $pack->isa($me)
!ll&&!rl&&r
36020
$pack ne __PACKAGE__ and $pack ne "Role::Tiny"
!ll&&!rl&&r
82820
MC/DC66%2/3
$pack ne __PACKAGE__ and $pack ne "Role::Tiny" and not $pack->isa($me)
$pack ne __PACKAGE__ $pack ne "Role::Tiny" not $pack->isa($me)
Truth table75%3/4
A and B and not(C)
A= $pack ne __PACKAGE__B= $pack ne "Role::Tiny"C= not $pack->isa($me)
ABCresult
0XX0
10X0
1100
1111
311 20 last;
312 }
313 }
314 20 ▶ _set_loaded($new_name, $file || (caller)[1]);
Condition33%1/3
$file || (caller)[1]
l!l&&r!l&&!r
2000
MC/DC0%0/2
$file || (caller)[1]
$file (caller)[1]
Truth table33%1/3
A || B
A= $fileB= (caller)[1]
ABresult
1X1
011
000
315  
316 20 return $new_name;
317 }
318  
319 11 ▶sub _gen_apply_defaults_for {
Subroutine _gen_apply_defaults_for: called CC=10 SCAR=23.1
320 11 my ($me, $class, @roles) = @_;
321  
322 11 ▶ my @attrs = map @{$INFO{$_}{attributes}||[]}, @roles;
Condition100%2/2
$Moo::Role::INFO{$_}{'attributes'} || []
l!l
711
MC/DC100%1/1
$Moo::Role::INFO{$_}{'attributes'} || []
$Moo::Role::INFO{$_}{'attributes'}
Truth table100%2/2
A
A= $Moo::Role::INFO{$_}{'attributes'}
Aresult
11
00
323  
324 11 my $con_gen;
325 my $m;
326  
327 return undef
328 11 ▶ unless $INC{'Moo.pm'}
Branch: 1 branch
BranchTrueFalseTotal
unless $INC{"Moo.pm"} and @attrs and $con_gen = "Moo"->_constructor_maker_for($class) and $m = "Moo"->_accessor_maker_for($class) 5 6 11
Condition66%6/9
$INC{"Moo.pm"} and @attrs and $con_gen = "Moo"->_constructor_maker_for($class) and $m = "Moo"->_accessor_maker_for($class)
!ll&&!rl&&r
506
$INC{"Moo.pm"} and @attrs and $con_gen = "Moo"->_constructor_maker_for($class)
!ll&&!rl&&r
506
$INC{"Moo.pm"} and @attrs
!ll&&!rl&&r
056
MC/DC25%1/4
$INC{"Moo.pm"} and @attrs and $con_gen = "Moo"->_constructor_maker_for($class) and $m = "Moo"->_accessor_maker_for($class)
$INC{"Moo.pm"} @attrs $con_gen = "Moo"->_constructor_maker_for($class) $m = "Moo"->_accessor_maker_for($class)
Truth table40%2/5
A and B and C and D
A= $INC{"Moo.pm"}B= @attrsC= $con_gen = "Moo"->_constructor_maker_for($class)D= $m = "Moo"->_accessor_maker_for($class)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
329 and @attrs
330 and $con_gen = Moo->_constructor_maker_for($class)
331 and $m = Moo->_accessor_maker_for($class);
332  
333 6 my $specs = $con_gen->all_attribute_specs;
334  
335 6 my %seen;
336 my %captures;
337 6 my @set;
338 6 ▶ while (my ($name, $spec) = splice @attrs, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@attrs, 0, 2)) 9 6 15
339 next
340 9 ▶ if $seen{$name}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$name}++ 0 9 9
341  
342 next
343 9 ▶ unless $m->has_eager_default($name, $spec);
Branch: 1 branch
BranchTrueFalseTotal
unless $m->has_eager_default($name, $spec) 2 7 9
344  
345 7 my ($has, $has_cap)
346 = $m->generate_simple_has('$_[0]', $name, $spec);
347 7 my ($set, $pop_cap)
348 = $m->generate_use_default('$_[0]', $name, $spec, $has);
349  
350 7 @captures{keys %$has_cap, keys %$pop_cap}
351 = (values %$has_cap, values %$pop_cap);
352  
353 7 push @set, $set;
354 }
355  
356 return undef
357 6 ▶ if !@set;
Branch: 1 branch
BranchTrueFalseTotal
unless @set 1 5 6
358  
359 5 my $code = join '', map "($_),", @set;
360 63 ▶ no warnings 'void';
Subroutine BEGIN: called CC=1 SCAR=0.0
361 5 require Sub::Quote;
362 5 return Sub::Quote::quote_sub(
363 "${class}::_apply_defaults",
364 $code,
365 \%captures,
366 {
367 package => $class,
368 no_install => 1,
369 no_defer => 1,
370 }
371 );
372 }
373  
374 12 ▶sub apply_roles_to_object {
Subroutine apply_roles_to_object: called CC=3 SCAR=11.0
Pod documented
375 12 my ($me, $object, @roles) = @_;
376 12 my $new = $me->SUPER::apply_roles_to_object($object, @roles);
377 12 my $class = ref $new;
378 12 _set_loaded($class, (caller)[1]);
379  
380 12 ▶ if (!exists $APPLY_DEFAULTS{$class}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Moo::Role::APPLY_DEFAULTS{$class}) 11 1 12
381 11 $APPLY_DEFAULTS{$class} = $me->_gen_apply_defaults_for($class, @roles);
382 }
383 12 ▶ if (my $apply_defaults = $APPLY_DEFAULTS{$class}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $apply_defaults = $Moo::Role::APPLY_DEFAULTS{$class}) 5 7 12
384 5 local $Carp::Internal{+__PACKAGE__} = 1;
385 5 local $Carp::Internal{$class} = 1;
386 5 $new->$apply_defaults;
387 }
388 11 return $new;
389 }
390  
391 19 ▶sub _install_single_modifier {
Subroutine _install_single_modifier: called CC=1 SCAR=0.0
392 19 my ($me, @args) = @_;
393 19 _install_modifier(@args);
394 }
395  
396 110 ▶sub _install_does {
Subroutine _install_does: called CC=2 SCAR=6.9
397 110 my ($me, $to) = @_;
398  
399 # If Role::Tiny actually installed the DOES, give it a name
400 110 ▶ my $new = $me->SUPER::_install_does($to) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $new = $me->SUPER::_install_does($to) or return 67 43 110
401 67 return _name_coderef("${to}::DOES", $new);
402 }
403  
404 12 ▶sub does_role {
Subroutine does_role: called CC=6 SCAR=18.0
Pod documented
405 12 my ($proto, $role) = @_;
406 12 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
if Role::Tiny::does_role($proto, $role) 7 5 12
407 if Role::Tiny::does_role($proto, $role);
408 5 my $meta;
409 5 ▶ if ($INC{'Moose.pm'}
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Moose.pm"} and $meta = Class::MOP::class_of($proto) and ref $meta ne "Moo::HandleMoose::FakeMetaClass" and $meta->can("does_role")) 2 3 5
Condition77%7/9
$INC{"Moose.pm"} and $meta = Class::MOP::class_of($proto) and ref $meta ne "Moo::HandleMoose::FakeMetaClass" and $meta->can("does_role")
!ll&&!rl&&r
302
$INC{"Moose.pm"} and $meta = Class::MOP::class_of($proto) and ref $meta ne "Moo::HandleMoose::FakeMetaClass"
!ll&&!rl&&r
212
$INC{"Moose.pm"} and $meta = Class::MOP::class_of($proto)
!ll&&!rl&&r
203
MC/DC50%2/4
$INC{"Moose.pm"} and $meta = Class::MOP::class_of($proto) and ref $meta ne "Moo::HandleMoose::FakeMetaClass" and $meta->can("does_role")
$INC{"Moose.pm"} $meta = Class::MOP::class_of($proto) ref $meta ne "Moo::HandleMoose::FakeMetaClass" $meta->can("does_role")
Truth table60%3/5
A and B and C and D
A= $INC{"Moose.pm"}B= $meta = Class::MOP::class_of($proto)C= ref $meta ne "Moo::HandleMoose::FakeMetaClass"D= $meta->can("does_role")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
410 and $meta = Class::MOP::class_of($proto)
411 and ref $meta ne 'Moo::HandleMoose::FakeMetaClass'
412 and $meta->can('does_role')
413 ) {
414 2 return $meta->does_role($role);
415 }
416 3 return 0;
417 }
418  
419 111 ▶sub _handle_constructor {
Subroutine _handle_constructor: called CC=13 SCAR=25.7
420 111 my ($me, $to, $role) = @_;
421 111 ▶ my $attr_info = $INFO{$role} && $INFO{$role}{attributes};
Condition66%2/3
$Moo::Role::INFO{$role} && $Moo::Role::INFO{$role}{'attributes'}
!ll&&!rl&&r
04467
MC/DC50%1/2
$Moo::Role::INFO{$role} && $Moo::Role::INFO{$role}{'attributes'}
$Moo::Role::INFO{$role} $Moo::Role::INFO{$role}{'attributes'}
Truth table66%2/3
A && B
A= $Moo::Role::INFO{$role}B= $Moo::Role::INFO{$role}{'attributes'}
ABresult
0X0
100
111
422 111 ▶ return unless $attr_info && @$attr_info;
Branch: 1 branch
BranchTrueFalseTotal
unless $attr_info and @$attr_info 46 65 111
Condition100%3/3
$attr_info and @$attr_info
!ll&&!rl&&r
44265
MC/DC100%2/2
$attr_info and @$attr_info
$attr_info @$attr_info
Truth table100%3/3
A and B
A= $attr_infoB= @$attr_info
ABresult
0X0
100
111
423 65 my $info = $INFO{$to};
424 65 ▶ my $con = $INC{"Moo.pm"} && Moo->_constructor_maker_for($to);
Condition100%3/3
$INC{'Moo.pm'} && 'Moo'->_constructor_maker_for($to)
!ll&&!rl&&r
2558
MC/DC100%2/2
$INC{'Moo.pm'} && 'Moo'->_constructor_maker_for($to)
$INC{'Moo.pm'} 'Moo'->_constructor_maker_for($to)
Truth table100%3/3
A && B
A= $INC{'Moo.pm'}B= 'Moo'->_constructor_maker_for($to)
ABresult
0X0
100
111
425 my %existing
426 5 ▶ = $info ? @{$info->{attributes} || []}
Branch: 1 branch
BranchTrueFalseTotal
$con ? : 58 1 59
Condition100%2/2
$info->{'attributes'} || []
l!l
23
MC/DC100%1/1
$info->{'attributes'} || []
$info->{'attributes'}
Truth table100%2/2
A
A= $info->{'attributes'}
Aresult
11
00
427 64 ▶ : $con ? %{$con->all_attribute_specs || {}}
Branch: 1 branch
BranchTrueFalseTotal
$info ? : 5 59 64
Condition100%2/2
$con->all_attribute_specs || {}
l!l
571
MC/DC100%1/1
$con->all_attribute_specs || {}
$con->all_attribute_specs
Truth table100%2/2
A
A= $con->all_attribute_specs
Aresult
11
00
428 : ();
429  
430 my @attr_info =
431 64 map { @{$attr_info}[$_, $_+1] }
432 69 grep { ! $existing{$attr_info->[$_]} }
433 64 map { 2 * $_ } 0..@$attr_info/2-1;
434  
435 64 ▶ if ($info) {
Branch: 2 branches
BranchTrueFalseTotal
if ($info) { } 5 59 64
elsif ($con) { } 58 1 59
436 5 ▶ push @{$info->{attributes}||=[]}, @attr_info;
Condition100%2/2
$info->{"attributes"} ||= []
l!l
23
MC/DC100%1/1
$info->{"attributes"} ||= []
$info->{"attributes"}
Truth table100%2/2
A
A= $info->{"attributes"}
Aresult
11
00
437 }
438 elsif ($con) {
439 # shallow copy of the specs since the constructor will assign an index
440 58 ▶ $con->register_attribute_specs(map ref() ? { %$_ } : $_, @attr_info);
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 59 59 118
441 }
442 }
443  
444 63 1;
445 __END__
« blib/lib/Moo/HandleMoose/_TypeMap.pm ↑ Summary blib/lib/Moo/_Utils.pm »