blib/lib/Moose/Meta/Role/Composite.pm

filter: Statementstmt 94.2% 82 / 87 Branchbran 75.0% 12 / 16 Conditioncond 50.0% 6 / 12 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 95.4% 21 / 22 Podpod 84.6% 11 / 13 totaltotal 84.8% 134 / 158 CC 14 SCAR 11.0
CC
14
Cov
87%
add_method
6.7
new
5.0
add_overloaded_operator
3.8
CRAP 3.0
« blib/lib/Moose/Meta/TypeConstraint/Enum.pm ↑ Summary blib/lib/Class/MOP/Instance.pm »
1 package Moose::Meta::Role::Composite;
2 385 our $VERSION = '2.4001';
3  
4 385 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 385 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 385 ▶use metaclass;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 385 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 385 ▶use Moose::Util 'throw_exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 385 ▶use parent 'Moose::Meta::Role';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # NOTE:
13 # we need to override the ->name
14 # method from Class::MOP::Package
15 # since we don't have an actual
16 # package for this.
17 # - SL
18 385 __PACKAGE__->meta->add_attribute('name' => (
19 reader => 'name',
20 Class::MOP::_definition_context(),
21 ));
22  
23 # NOTE:
24 # Again, since we don't have a real
25 # package to store our methods in,
26 # we use a HASH ref instead.
27 # - SL
28 __PACKAGE__->meta->add_attribute('_methods' => (
29 reader => '_method_map',
30 258 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
31 385 Class::MOP::_definition_context(),
32 ));
33  
34 __PACKAGE__->meta->add_attribute('_overloads' => (
35 reader => '_overload_map',
36 258 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
37 385 Class::MOP::_definition_context(),
38 ));
39  
40 385 __PACKAGE__->meta->add_attribute('_overload_fallback' => (
41 accessor => '_overload_fallback',
42 Class::MOP::_definition_context(),
43 ));
44  
45 385 __PACKAGE__->meta->add_attribute(
46 'application_role_summation_class',
47 reader => 'application_role_summation_class',
48 default => 'Moose::Meta::Role::Application::RoleSummation',
49 Class::MOP::_definition_context(),
50 );
51  
52 259 ▶sub new {
Subroutine new: called CC=5 SCAR=16.1
Pod documented
53 259 my ($class, %params) = @_;
54  
55 # the roles param is required ...
56 259 foreach ( @{$params{roles}} ) {
57 582 ▶ unless ( $_->isa('Moose::Meta::Role') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_->isa("Moose::Meta::Role")) 1 581 582
58 1 throw_exception( RolesListMustBeInstancesOfMooseMetaRole => params => \%params,
59 role => $_,
60 class => $class
61 );
62 }
63 }
64  
65 my @composition_roles = map {
66 581 $_->composition_class_roles
67 258 } @{ $params{roles} };
68  
69 258 ▶ if (@composition_roles) {
Branch: 1 branch
BranchTrueFalseTotal
if (@composition_roles) 3 255 258
70 3 my $meta = Moose::Meta::Class->create_anon_class(
71 superclasses => [ $class ],
72 roles => [ @composition_roles ],
73 cache => 1,
74 );
75 3 $class = $meta->name;
76 }
77  
78 # and the name is created from the
79 # roles if one has not been provided
80 258 ▶ $params{name} ||= (join "|" => map { $_->name } @{$params{roles}});
Condition33%1/3
$params{"name"} ||= join("|", map({$_->name;} @{$params{"roles"};}))
l!l&&r!l&&!r
02580
MC/DC0%0/2
$params{"name"} ||= join("|", map({$_->name;} @{$params{"roles"};}))
$params{"name"} join("|", map({$_->name;} @{$params{"roles"};}))
Truth table33%1/3
A ||= B
A= $params{"name"}B= join("|", map({$_->name;} @{$params{"roles"};}))
ABresult
1X1
011
000
81 258 $class->_new(\%params);
82 }
83  
84 # There's no such thing as an anonymous composite role since composites are an
85 # artifact of Moose's internals. However, a composite role that contains an
86 # anon role may _look_ like an anon role since $self->name =~ /$anon_key/ can
87 # return true if the first role in the composite is anonymous itself.
88 63 ▶sub is_anon { 0 }
Subroutine is_anon: called CC=1 SCAR=0.0
Pod documented
89  
90 # This is largely a copy of what's in Moose::Meta::Role (itself
91 # largely a copy of Class::MOP::Class). However, we can't actually
92 # call add_package_symbol, because there's no package into which to
93 # add the symbol.
94 1502 ▶sub add_method {
Subroutine add_method: called CC=6 SCAR=19.1
Pod documented
95 1502 my ($self, $method_name, $method) = @_;
96  
97 1502 ▶ unless ( defined $method_name && $method_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $method_name and $method_name) 1 1501 1502
Condition66%2/3
defined $method_name and $method_name
!ll&&!rl&&r
101501
MC/DC50%1/2
defined $method_name and $method_name
defined $method_name $method_name
Truth table66%2/3
A and B
A= defined $method_nameB= $method_name
ABresult
0X0
100
111
98 1 throw_exception( MustDefineAMethodName => instance => $self );
99 }
100  
101 1501 my $body;
102 1501 ▶ if (blessed($method)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($method)) { } 1501 0 1501
103 1501 $body = $method->body;
104 1501 ▶ if ($method->package_name ne $self->name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method->package_name ne $self->name) 1501 0 1501
105 1501 ▶ $method = $method->clone(
Branch: 1 branch
BranchTrueFalseTotal
if $method->can("clone") 1501 0 1501
106 package_name => $self->name,
107 name => $method_name
108 ) if $method->can('clone');
109 }
110 }
111 else {
112 0 $body = $method;
113 0 $method = $self->wrap_method_body( body => $body, name => $method_name );
114 }
115  
116 1501 $self->_method_map->{$method_name} = $method;
117 }
118  
119 4 ▶sub get_method_list {
Subroutine get_method_list: called CC=1 SCAR=0.0
Pod documented
120 4 my $self = shift;
121 4 return keys %{ $self->_method_map };
122 }
123  
124 200 ▶sub _get_local_methods {
Subroutine _get_local_methods: called CC=1 SCAR=0.0
125 200 my $self = shift;
126 200 return values %{ $self->_method_map };
127 }
128  
129 498 ▶sub has_method {
Subroutine has_method: called CC=1 SCAR=0.0
Pod documented
130 498 my ($self, $method_name) = @_;
131  
132 498 return exists $self->_method_map->{$method_name};
133 }
134  
135 0 ▶sub get_method {
Subroutine get_method: not called CC=1 SCAR=6.9
Pod documented
136 0 my ($self, $method_name) = @_;
137  
138 0 return $self->_method_map->{$method_name};
139 }
140  
141 200 ▶sub is_overloaded {
Subroutine is_overloaded: called CC=1 SCAR=0.0
Pod documented
142 200 my ($self) = @_;
143 200 return keys %{ $self->_overload_map };
144 }
145  
146 4 ▶sub add_overloaded_operator {
Subroutine add_overloaded_operator: called CC=3 SCAR=13.3
Pod documented
147 4 my ( $self, $op_name, $overload ) = @_;
148  
149 4 ▶ unless ( defined $op_name && $op_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $op_name and $op_name) 0 4 4
Condition33%1/3
defined $op_name and $op_name
!ll&&!rl&&r
004
MC/DC0%0/2
defined $op_name and $op_name
defined $op_name $op_name
Truth table33%1/3
A and B
A= defined $op_nameB= $op_name
ABresult
0X0
100
111
150 0 throw_exception(
151 'MustDefineAnOverloadOperator',
152 instance => $self,
153 );
154 }
155  
156 4 $self->_overload_map->{$op_name} = $overload;
157 }
158  
159 4 ▶sub get_overload_fallback_value {
Subroutine get_overload_fallback_value: called CC=1 SCAR=0.0
Pod undocumented
160 4 my ($self) = @_;
161 4 return $self->_overload_fallback;
162 }
163  
164 8 ▶sub set_overload_fallback_value {
Subroutine set_overload_fallback_value: called CC=1 SCAR=0.0
Pod undocumented
165 8 my $self = shift;
166 8 $self->_overload_fallback(shift);
167 }
168  
169 4 ▶sub get_all_overloaded_operators {
Subroutine get_all_overloaded_operators: called CC=1 SCAR=0.0
Pod documented
170 4 my ( $self, $method_name ) = @_;
171 4 return values %{ $self->_overload_map };
172 }
173  
174 231 ▶sub apply_params {
Subroutine apply_params: called CC=1 SCAR=0.0
Pod documented
175 231 my ($self, $role_params) = @_;
176 231 Moose::Util::_load_user_class($self->application_role_summation_class);
177  
178 231 $self->application_role_summation_class->new(
179 role_params => $role_params,
180 )->apply($self);
181  
182 216 return $self;
183 }
184  
185 4 ▶sub reinitialize {
Subroutine reinitialize: called CC=3 SCAR=11.0
Pod documented
186 4 my ( $class, $old_meta, @args ) = @_;
187  
188 4 ▶ throw_exception( CannotInitializeMooseMetaRoleComposite => old_meta => $old_meta,
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($old_meta) and $old_meta->isa("Moose::Meta::Role::Composite") 1 3 4
Condition66%2/3
builtin::blessed($old_meta) and $old_meta->isa("Moose::Meta::Role::Composite")
!ll&&!rl&&r
103
MC/DC50%1/2
builtin::blessed($old_meta) and $old_meta->isa("Moose::Meta::Role::Composite")
builtin::blessed($old_meta) $old_meta->isa("Moose::Meta::Role::Composite")
Truth table66%2/3
A and B
A= builtin::blessed($old_meta)B= $old_meta->isa("Moose::Meta::Role::Composite")
ABresult
0X0
100
111
189 args => \@args,
190 role_composite => $class
191 )
192 if !blessed $old_meta
193 || !$old_meta->isa('Moose::Meta::Role::Composite');
194  
195 3 my %existing_classes = map { $_ => $old_meta->$_() } qw(
196 application_role_summation_class
197 );
198  
199 3 return $old_meta->meta->clone_object( $old_meta, %existing_classes, @args );
200 }
201  
202 385 1;
203  
204 # ABSTRACT: An object to represent the set of roles
205  
206 __END__
« blib/lib/Moose/Meta/TypeConstraint/Enum.pm ↑ Summary blib/lib/Class/MOP/Instance.pm »