blib/lib/Moose/Role.pm

filter: Statementstmt 98.9% 96 / 97 Branchbran 91.1% 31 / 34 Conditioncond 80.0% 4 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 26 / 26 Podpod 15.3% 2 / 13 totaltotal 89.8% 160 / 178 CC 21 SCAR 16.7
CC
21
Cov
96%
init_meta
14.1
has
4.0
super
2.1
CRAP 5.3
« blib/lib/Moose/Exception/InvalidArgPassedToMooseUtilMetaRole.pm ↑ Summary blib/lib/Moose/Meta/Class.pm »
1 270 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 270 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Moose::Role;
4 270 our $VERSION = '2.4001';
5  
6 270 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 270 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 270 ▶use Class::Load 'is_class_loaded';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 270 ▶use Module::Runtime 'module_notional_filename';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 270 ▶use Sub::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 270 ▶use Moose ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 270 ▶use Moose::Util 'throw_exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 270 ▶use Moose::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 270 ▶use Moose::Meta::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 270 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 ▶sub extends {
Subroutine extends: called CC=1 SCAR=0.0
Pod undocumented
21 2 throw_exception("RolesDoNotSupportExtends");
22 }
23  
24 507 ▶sub with {
Subroutine with: called CC=1 SCAR=0.0
Pod undocumented
25 507 Moose::Util::apply_all_roles( shift, @_ );
26 }
27  
28 165 ▶sub requires {
Subroutine requires: called CC=2 SCAR=6.9
Pod documented
29 165 my $meta = shift;
30 165 ▶ throw_exception( MustSpecifyAtleastOneMethod => role_name => $meta->name ) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 164 165
31 164 $meta->add_required_methods(@_);
32 }
33  
34 9 ▶sub excludes {
Subroutine excludes: called CC=2 SCAR=6.9
Pod documented
35 9 my $meta = shift;
36 9 ▶ throw_exception( MustSpecifyAtleastOneRole => role_name => $meta->name ) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 8 9
37 8 $meta->add_excluded_roles(@_);
38 }
39  
40 429 ▶sub has {
Subroutine has: called CC=4 SCAR=13.9
Pod undocumented
41 429 my $meta = shift;
42 429 my $name = shift;
43 429 ▶ throw_exception( InvalidHasProvidedInARole => role_name => $meta->name,
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 1 428 429
44 attribute_name => $name,
45 )
46 if @_ == 1;
47 428 my %context = Moose::Util::_caller_info;
48 428 $context{context} = 'has declaration';
49 428 $context{type} = 'role';
50 428 my %options = ( definition_context => \%context, @_ );
51 428 ▶ my $attrs = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ];
Branch: 1 branch
BranchTrueFalseTotal
ref $name eq 'ARRAY' ? : 1 427 428
52 428 $meta->add_attribute( $_, %options ) for @$attrs;
53 }
54  
55 395 ▶sub _add_method_modifier {
Subroutine _add_method_modifier: called CC=2 SCAR=6.9
56 395 my $type = shift;
57 395 my $meta = shift;
58  
59 395 ▶ if ( ref($_[0]) eq 'Regexp' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq "Regexp") 5 390 395
60 5 throw_exception( RolesDoNotSupportRegexReferencesForMethodModifiers => modifier_type => $type,
61 role_name => $meta->name,
62 );
63 }
64  
65 390 Moose::Util::add_method_modifier($meta, $type, \@_);
66 }
67  
68 106 ▶sub before { _add_method_modifier('before', @_) }
Subroutine before: called CC=1 SCAR=0.0
Pod undocumented
69  
70 35 ▶sub after { _add_method_modifier('after', @_) }
Subroutine after: called CC=1 SCAR=0.0
Pod undocumented
71  
72 254 ▶sub around { _add_method_modifier('around', @_) }
Subroutine around: called CC=1 SCAR=0.0
Pod undocumented
73  
74 # see Moose.pm for discussion
75 2241 ▶sub super {
Subroutine super: called CC=2 SCAR=7.2
Pod undocumented
76 2241 ▶ return unless $Moose::SUPER_BODY;
Branch: 1 branch
BranchTrueFalseTotal
unless $Moose::SUPER_BODY 0 2241 2241
77 2241 $Moose::SUPER_BODY->(@Moose::SUPER_ARGS);
78 }
79  
80 167 ▶sub override {
Subroutine override: called CC=1 SCAR=0.0
Pod undocumented
81 167 my $meta = shift;
82 167 my ( $name, $code ) = @_;
83 167 $meta->add_override_method_modifier( $name, $code );
84 }
85  
86 2 ▶sub inner {
Subroutine inner: called CC=1 SCAR=0.0
Pod undocumented
87 2 throw_exception("RolesDoNotSupportInner");
88 }
89  
90 2 ▶sub augment {
Subroutine augment: called CC=1 SCAR=0.0
Pod undocumented
91 2 throw_exception("RolesDoNotSupportAugment");
92 }
93  
94 270 Moose::Exporter->setup_import_methods(
95 with_meta => [
96 qw( with requires excludes has before after around override )
97 ],
98 as_is => [
99 qw( extends super inner augment ),
100 'Carp::confess',
101 'Scalar::Util::blessed',
102 ],
103 );
104  
105 1304 ▶sub init_meta {
Subroutine init_meta: called CC=14 SCAR=26.5
Pod undocumented
106 1304 shift;
107 1304 my %args = @_;
108  
109 1304 my $role = $args{for_class};
110  
111 1304 ▶ unless ($role) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($role) 1 1303 1304
112 1 require Moose;
113 1 throw_exception( InitMetaRequiresClass => params => \%args );
114 }
115  
116 1303 ▶ my $metaclass = $args{metaclass} || "Moose::Meta::Role";
Condition100%2/2
$args{'metaclass'} || 'Moose::Meta::Role'
l!l
51298
MC/DC100%1/1
$args{'metaclass'} || 'Moose::Meta::Role'
$args{'metaclass'}
Truth table100%2/2
A
A= $args{'metaclass'}
Aresult
11
00
117 1303 ▶ my $meta_name = exists $args{meta_name} ? $args{meta_name} : 'meta';
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'meta_name'} ? : 1299 4 1303
118  
119 1303 ▶ throw_exception( MetaclassNotLoaded => class_name => $metaclass )
Branch: 1 branch
BranchTrueFalseTotal
unless is_class_loaded($metaclass) 2 1301 1303
120 unless is_class_loaded($metaclass);
121  
122 1301 ▶ throw_exception( MetaclassMustBeASubclassOfMooseMetaRole => role_name => $metaclass )
Branch: 1 branch
BranchTrueFalseTotal
unless $metaclass->isa("Moose::Meta::Role") 1 1300 1301
123 unless $metaclass->isa('Moose::Meta::Role');
124  
125 # make a subtype for each Moose role
126 1300 ▶ role_type $role unless find_type_constraint($role);
Branch: 1 branch
BranchTrueFalseTotal
unless find_type_constraint($role) 1279 21 1300
127  
128 1300 my $meta;
129 1300 ▶ if ( $meta = Class::MOP::get_metaclass_by_name($role) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta = Class::MOP::get_metaclass_by_name($role)) { } 22 1278 1300
130 22 ▶ unless ( $meta->isa("Moose::Meta::Role") ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($meta->isa("Moose::Meta::Role")) 2 20 22
131 2 ▶ if ( $meta->isa('Moose::Meta::Class') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->isa('Moose::Meta::Class')) { } 1 1 2
132 1 throw_exception( MetaclassIsAClassNotASubclassOfGivenMetaclass => class_name => $role,
133 metaclass => $metaclass,
134 );
135 } else {
136 1 throw_exception( MetaclassIsNotASubclassOfGivenMetaclass => class_name => $role,
137 metaclass => $metaclass,
138 );
139 }
140 }
141 }
142 else {
143 1278 $meta = $metaclass->initialize($role);
144 1278 my $filename = module_notional_filename($meta->name);
145 $INC{$filename} = '(set by Moose)'
146 1278 ▶ unless exists $INC{$filename};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $INC{$filename} 440 838 1278
147 }
148  
149 1298 ▶ if (defined $meta_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $meta_name) 1298 0 1298
150 # also check for inherited non moose 'meta' method?
151 1298 my $existing = $meta->get_method($meta_name);
152 1298 ▶ if ($existing && !$existing->isa('Class::MOP::Method::Meta')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($existing and not $existing->isa("Class::MOP::Method::Meta")) 0 1298 1298
Condition66%2/3
$existing and not $existing->isa("Class::MOP::Method::Meta")
!ll&&!rl&&r
1278200
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
153 0 Carp::cluck "Moose::Role is overwriting an existing method named "
154 . "$meta_name in role $role with a method "
155 . "which returns the class's metaclass. If this is "
156 . "actually what you want, you should remove the "
157 . "existing method, otherwise, you should rename or "
158 . "disable this generated method using the "
159 . "'-meta_name' option to 'use Moose::Role'.";
160 }
161 1298 $meta->_add_meta_method($meta_name);
162 }
163  
164 1298 return $meta;
165 }
166  
167 270 1;
168  
169 # ABSTRACT: The Moose Role
170  
171 __END__
« blib/lib/Moose/Exception/InvalidArgPassedToMooseUtilMetaRole.pm ↑ Summary blib/lib/Moose/Meta/Class.pm »