blib/lib/Moose.pm

filter: Statementstmt 98.7% 161 / 163 Branchbran 92.8% 39 / 42 Conditioncond 91.6% 11 / 12 MC/DCmcdc 71.4% 5 / 7 Subroutinesub 97.4% 38 / 39 Podpod 83.3% 10 / 12 totaltotal 96.0% 264 / 275 CC 28 SCAR 19.8
CC
28
Cov
97%
init_meta
20.1
super
5.0
has
3.0
CRAP 7.2
« blib/lib/Class/MOP/Overload.pm ↑ Summary blib/lib/Moose/Meta/Role/Application/RoleSummation.pm »
1 385 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 385 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Moose; # git description: 2.4000-4-gac847aa11
4 385 our $VERSION = '2.4001';
5 385 our $AUTHORITY = 'cpan:STEVAN';
6  
7 385 ▶use 5.008003;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 385 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 385 ▶use Carp 'carp';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 385 ▶use Module::Runtime 'module_notional_filename';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 385 ▶use Class::Load 'is_class_loaded';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 385 ▶use Moose::Deprecated;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 385 ▶use Moose::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 385 ▶use Class::MOP;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 385 ▶die "Class::MOP version $Moose::VERSION required--this is version $Class::MOP::VERSION"
Branch: 1 branch
BranchTrueFalseTotal
if $Class::MOP::VERSION ne $Moose::VERSION 0 385 385
20 if $Class::MOP::VERSION ne $Moose::VERSION;
21  
22 385 ▶use Moose::Meta::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 385 ▶use Moose::Meta::TypeConstraint;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 385 ▶use Moose::Meta::TypeCoercion;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 385 ▶use Moose::Meta::Attribute;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 385 ▶use Moose::Meta::Instance;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 385 ▶use Moose::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 385 ▶use Moose::Meta::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 385 ▶use Moose::Meta::Role::Composite;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 385 ▶use Moose::Meta::Role::Application;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 385 ▶use Moose::Meta::Role::Application::RoleSummation;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 385 ▶use Moose::Meta::Role::Application::ToClass;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 385 ▶use Moose::Meta::Role::Application::ToRole;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 385 ▶use Moose::Meta::Role::Application::ToInstance;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 385 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 385 ▶use Moose::Util 'throw_exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 385 ▶use Moose::Meta::Attribute::Native;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 634 ▶sub extends {
Subroutine extends: called CC=2 SCAR=6.9
Pod documented
44 634 my $meta = shift;
45  
46 634 ▶ unless ( @_ )
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 1 633 634
47 {
48 1 throw_exception( ExtendsMissingArgs => class_name => $meta->name );
49 }
50 # this checks the metaclass to make sure
51 # it is correct, sometimes it can get out
52 # of sync when the classes are being built
53 633 $meta->superclasses(@_);
54 }
55  
56 554 ▶sub with {
Subroutine with: called CC=1 SCAR=0.0
Pod documented
57 554 Moose::Util::apply_all_roles(shift, @_);
58 }
59  
60 2 ▶sub throw_error {
Subroutine throw_error: called CC=1 SCAR=0.0
Pod undocumented
61 2 shift;
62 2 Class::MOP::Object->throw_error(@_);
63 }
64  
65 1492 ▶sub has {
Subroutine has: called CC=3 SCAR=11.0
Pod documented
66 1492 my $meta = shift;
67 1492 my $name = shift;
68  
69 1492 my %context = Moose::Util::_caller_info;
70 1492 $context{context} = 'has declaration';
71 1492 $context{type} = 'class';
72 1492 my @options = ( definition_context => \%context, @_ );
73 1492 ▶ my $attrs = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ];
Branch: 1 branch
BranchTrueFalseTotal
ref $name eq 'ARRAY' ? : 19 1473 1492
74 1492 $meta->add_attribute( $_, @options ) for @$attrs;
75 }
76  
77 9 ▶sub before {
Subroutine before: called CC=1 SCAR=0.0
Pod documented
78 9 Moose::Util::add_method_modifier(shift, 'before', \@_);
79 }
80  
81 6 ▶sub after {
Subroutine after: called CC=1 SCAR=0.0
Pod documented
82 6 Moose::Util::add_method_modifier(shift, 'after', \@_);
83 }
84  
85 9 ▶sub around {
Subroutine around: called CC=1 SCAR=0.0
Pod documented
86 9 Moose::Util::add_method_modifier(shift, 'around', \@_);
87 }
88  
89 385 our $SUPER_PACKAGE;
90 385 our $SUPER_BODY;
91 385 our @SUPER_ARGS;
92  
93 19 ▶sub super {
Subroutine super: called CC=5 SCAR=16.1
Pod documented
94 19 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 18 19
95 1 carp 'Arguments passed to super() are ignored';
96 }
97  
98 # This check avoids a recursion loop - see
99 # t/bugs/super_recursion.t
100 19 ▶ return if defined $SUPER_PACKAGE && $SUPER_PACKAGE ne caller();
Branch: 1 branch
BranchTrueFalseTotal
if defined $Moose::SUPER_PACKAGE and $Moose::SUPER_PACKAGE ne caller() 1 18 19
Condition100%3/3
defined $Moose::SUPER_PACKAGE and $Moose::SUPER_PACKAGE ne caller()
!ll&&!rl&&r
1171
MC/DC100%2/2
defined $Moose::SUPER_PACKAGE and $Moose::SUPER_PACKAGE ne caller()
defined $Moose::SUPER_PACKAGE $Moose::SUPER_PACKAGE ne caller()
Truth table100%3/3
A and B
A= defined $Moose::SUPER_PACKAGEB= $Moose::SUPER_PACKAGE ne caller()
ABresult
0X0
100
111
101 18 ▶ return unless $SUPER_BODY; $SUPER_BODY->(@SUPER_ARGS);
Branch: 1 branch
BranchTrueFalseTotal
unless $Moose::SUPER_BODY 1 17 18
102 }
103  
104 20 ▶sub override {
Subroutine override: called CC=1 SCAR=0.0
Pod documented
105 20 my $meta = shift;
106 20 my ( $name, $method ) = @_;
107 20 $meta->add_override_method_modifier( $name => $method );
108 }
109  
110 27 ▶sub inner {
Subroutine inner: called CC=2 SCAR=6.9
Pod documented
111 27 my $pkg = caller();
112 27 our ( %INNER_BODY, %INNER_ARGS );
113  
114 27 ▶ if ( my $body = $INNER_BODY{$pkg} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $body = $Moose::INNER_BODY{$pkg}) { } 19 8 27
115 19 my @args = @{ $INNER_ARGS{$pkg} };
116 19 local $INNER_ARGS{$pkg};
117 19 local $INNER_BODY{$pkg};
118 19 return $body->(@args);
119 } else {
120 8 return;
121 }
122 }
123  
124 16 ▶sub augment {
Subroutine augment: called CC=1 SCAR=0.0
Pod documented
125 16 my $meta = shift;
126 16 my ( $name, $method ) = @_;
127 16 $meta->add_augment_method_modifier( $name => $method );
128 }
129  
130 385 Moose::Exporter->setup_import_methods(
131 with_meta => [
132 qw( extends with has before after around override augment )
133 ],
134 as_is => [
135 qw( super inner ),
136 'Carp::confess',
137 'Scalar::Util::blessed',
138 ],
139 );
140  
141 1536 ▶sub init_meta {
Subroutine init_meta: called CC=20 SCAR=30.0
Pod undocumented
142 1536 shift;
143 1536 my %args = @_;
144  
145 my $class = $args{for_class}
146 1536 ▶ or throw_exception( InitMetaRequiresClass => params => \%args );
Branch: 1 branch
BranchTrueFalseTotal
my $class = $args{"for_class"} or throw_exception("InitMetaRequiresClass", "params", \%args) 1535 1 1536
147  
148 1535 ▶ my $base_class = $args{base_class} || 'Moose::Object';
Condition100%2/2
$args{'base_class'} || 'Moose::Object'
l!l
31532
MC/DC100%1/1
$args{'base_class'} || 'Moose::Object'
$args{'base_class'}
Truth table100%2/2
A
A= $args{'base_class'}
Aresult
11
00
149 1535 ▶ my $metaclass = $args{metaclass} || 'Moose::Meta::Class';
Condition100%2/2
$args{'metaclass'} || 'Moose::Meta::Class'
l!l
131522
MC/DC100%1/1
$args{'metaclass'} || 'Moose::Meta::Class'
$args{'metaclass'}
Truth table100%2/2
A
A= $args{'metaclass'}
Aresult
11
00
150 1535 ▶ my $meta_name = exists $args{meta_name} ? $args{meta_name} : 'meta';
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'meta_name'} ? : 1529 6 1535
151  
152 1535 ▶ throw_exception( MetaclassNotLoaded => class_name => $metaclass )
Branch: 1 branch
BranchTrueFalseTotal
unless is_class_loaded($metaclass) 2 1533 1535
153 unless is_class_loaded($metaclass);
154  
155 1533 ▶ throw_exception( MetaclassMustBeASubclassOfMooseMetaClass => class_name => $metaclass )
Branch: 1 branch
BranchTrueFalseTotal
unless $metaclass->isa("Moose::Meta::Class") 1 1532 1533
156 unless $metaclass->isa('Moose::Meta::Class');
157  
158 # make a subtype for each Moose class
159 1532 ▶ class_type($class)
Branch: 1 branch
BranchTrueFalseTotal
unless find_type_constraint($class) 1470 62 1532
160 unless find_type_constraint($class);
161  
162 1532 my $meta;
163  
164 1532 ▶ if ( $meta = Class::MOP::get_metaclass_by_name($class) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta = Class::MOP::get_metaclass_by_name($class)) { } 70 1462 1532
165 70 ▶ unless ( $meta->isa("Moose::Meta::Class") ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($meta->isa("Moose::Meta::Class")) 3 67 70
166 3 ▶ if ( $meta->isa('Moose::Meta::Role') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->isa('Moose::Meta::Role')) { } 1 2 3
167 1 throw_exception( MetaclassIsARoleNotASubclassOfGivenMetaclass => role_name => $class,
168 metaclass => $metaclass,
169 role => $meta
170 );
171 } else {
172 2 throw_exception( MetaclassIsNotASubclassOfGivenMetaclass => class_name => $class,
173 metaclass => $metaclass,
174 class => $meta
175 );
176 }
177 }
178 } else {
179 # no metaclass
180  
181 # now we check whether our ancestors have metaclass, and if so borrow that
182 1462 my ( undef, @isa ) = @{ mro::get_linear_isa($class) };
183  
184 1462 foreach my $ancestor ( @isa ) {
185 8 ▶ my $ancestor_meta = Class::MOP::get_metaclass_by_name($ancestor) || next;
Condition100%2/2
Class::MOP::get_metaclass_by_name($ancestor) || (next)
l!l
44
MC/DC100%1/1
Class::MOP::get_metaclass_by_name($ancestor) || (next)
Class::MOP::get_metaclass_by_name($ancestor)
Truth table100%2/2
A
A= Class::MOP::get_metaclass_by_name($ancestor)
Aresult
11
00
186  
187 4 my $ancestor_meta_class = $ancestor_meta->_real_ref_name;
188  
189 # if we have an ancestor metaclass that inherits $metaclass, we use
190 # that. This is like _fix_metaclass_incompatibility, but we can do it now.
191  
192 # the case of having an ancestry is not very common, but arises in
193 # e.g. Reaction
194 4 ▶ unless ( $metaclass->isa( $ancestor_meta_class ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($metaclass->isa($ancestor_meta_class)) 1 3 4
195 1 ▶ if ( $ancestor_meta_class->isa($metaclass) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ancestor_meta_class->isa($metaclass)) 1 0 1
196 1 $metaclass = $ancestor_meta_class;
197 }
198 }
199 }
200  
201 1462 $meta = $metaclass->initialize($class);
202 1462 my $filename = module_notional_filename($meta->name);
203 $INC{$filename} = '(set by Moose)'
204 1462 ▶ unless exists $INC{$filename};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $INC{$filename} 831 631 1462
205 }
206  
207 1529 ▶ if (defined $meta_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $meta_name) 1528 1 1529
208 # also check for inherited non moose 'meta' method?
209 1528 my $existing = $meta->get_method($meta_name);
210 1528 ▶ if ($existing && !$existing->isa('Class::MOP::Method::Meta')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($existing and not $existing->isa("Class::MOP::Method::Meta")) 0 1528 1528
Condition66%2/3
$existing and not $existing->isa("Class::MOP::Method::Meta")
!ll&&!rl&&r
1462660
MC/DC0%0/2
$existing and not $existing->isa("Class::MOP::Method::Meta")
$existing not $existing->isa("Class::MOP::Method::Meta")
Truth table66%2/3
A and not(B)
A= $existingB= not $existing->isa("Class::MOP::Method::Meta")
ABresult
0X0
100
111
211 0 Carp::cluck "Moose is overwriting an existing method named "
212 . "$meta_name in class $class with a method "
213 . "which returns the class's metaclass. If this is "
214 . "actually what you want, you should remove the "
215 . "existing method, otherwise, you should rename or "
216 . "disable this generated method using the "
217 . "'-meta_name' option to 'use Moose'.";
218 }
219 1528 $meta->_add_meta_method($meta_name);
220 }
221  
222 # make sure they inherit from Moose::Object
223 1529 ▶ $meta->superclasses($base_class)
Branch: 1 branch
BranchTrueFalseTotal
unless $meta->superclasses 1466 63 1529
224 unless $meta->superclasses();
225  
226 1529 return $meta;
227 }
228  
229 # This may be used in some older MooseX extensions.
230 0 ▶sub _get_caller {
Subroutine _get_caller: not called CC=1 SCAR=6.9
231 0 goto &Moose::Exporter::_get_caller;
232 }
233  
234 ## make 'em all immutable
235  
236 $_->make_immutable(
237 inline_constructor => 1,
238 constructor_name => "_new",
239 # these are Class::MOP accessors, so they need inlining
240 inline_accessors => 1
241 385 ) for grep { $_->is_mutable }
242 8085 map { $_->meta }
243 qw(
244 Moose::Meta::Attribute
245 Moose::Meta::Class
246 Moose::Meta::Instance
247  
248 Moose::Meta::TypeCoercion
249 Moose::Meta::TypeCoercion::Union
250  
251 Moose::Meta::Method
252 Moose::Meta::Method::Constructor
253 Moose::Meta::Method::Destructor
254 Moose::Meta::Method::Overridden
255 Moose::Meta::Method::Augmented
256  
257 Moose::Meta::Role
258 Moose::Meta::Role::Attribute
259 Moose::Meta::Role::Method
260 Moose::Meta::Role::Method::Required
261 Moose::Meta::Role::Method::Conflicting
262  
263 Moose::Meta::Role::Composite
264  
265 Moose::Meta::Role::Application
266 Moose::Meta::Role::Application::RoleSummation
267 Moose::Meta::Role::Application::ToClass
268 Moose::Meta::Role::Application::ToRole
269 Moose::Meta::Role::Application::ToInstance
270 );
271  
272 $_->make_immutable(
273 inline_constructor => 0,
274 constructor_name => undef,
275 # these are Class::MOP accessors, so they need inlining
276 inline_accessors => 1
277 385 ) for grep { $_->is_mutable }
278 1155 map { $_->meta }
279 qw(
280 Moose::Meta::Method::Accessor
281 Moose::Meta::Method::Delegation
282 Moose::Meta::Mixin::AttributeCore
283 );
284  
285 385 1;
286  
287 # ABSTRACT: A postmodern object system for Perl 5
288  
289 __END__
« blib/lib/Class/MOP/Overload.pm ↑ Summary blib/lib/Moose/Meta/Role/Application/RoleSummation.pm »