Filename | /Users/ap13/perl5/lib/perl5/darwin-2level/Moose/Meta/Role/Composite.pm |
Statements | Executed 19 statements in 1.16ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 18µs | 39µs | BEGIN@4 | Moose::Meta::Role::Composite::
1 | 1 | 1 | 13µs | 56µs | BEGIN@10 | Moose::Meta::Role::Composite::
1 | 1 | 1 | 12µs | 54µs | BEGIN@8 | Moose::Meta::Role::Composite::
1 | 1 | 1 | 12µs | 243µs | BEGIN@9 | Moose::Meta::Role::Composite::
1 | 1 | 1 | 11µs | 703µs | BEGIN@6 | Moose::Meta::Role::Composite::
1 | 1 | 1 | 11µs | 18µs | BEGIN@5 | Moose::Meta::Role::Composite::
0 | 0 | 0 | 0s | 0s | __ANON__[:30] | Moose::Meta::Role::Composite::
0 | 0 | 0 | 0s | 0s | __ANON__[:36] | Moose::Meta::Role::Composite::
0 | 0 | 0 | 0s | 0s | _get_local_methods | Moose::Meta::Role::Composite::
0 | 0 | 0 | 0s | 0s | add_method | Moose::Meta::Role::Composite::
0 | 0 | 0 | 0s | 0s | add_overloaded_operator | Moose::Meta::Role::Composite::
0 | 0 | 0 | 0s | 0s | apply_params | Moose::Meta::Role::Composite::
0 | 0 | 0 | 0s | 0s | get_all_overloaded_operators | Moose::Meta::Role::Composite::
0 | 0 | 0 | 0s | 0s | get_method | Moose::Meta::Role::Composite::
0 | 0 | 0 | 0s | 0s | get_method_list | Moose::Meta::Role::Composite::
0 | 0 | 0 | 0s | 0s | get_overload_fallback_value | Moose::Meta::Role::Composite::
0 | 0 | 0 | 0s | 0s | has_method | Moose::Meta::Role::Composite::
0 | 0 | 0 | 0s | 0s | is_anon | Moose::Meta::Role::Composite::
0 | 0 | 0 | 0s | 0s | is_overloaded | Moose::Meta::Role::Composite::
0 | 0 | 0 | 0s | 0s | new | Moose::Meta::Role::Composite::
0 | 0 | 0 | 0s | 0s | reinitialize | Moose::Meta::Role::Composite::
0 | 0 | 0 | 0s | 0s | set_overload_fallback_value | Moose::Meta::Role::Composite::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Moose::Meta::Role::Composite; | ||||
2 | 1 | 800ns | our $VERSION = '2.1403'; | ||
3 | |||||
4 | 2 | 30µs | 2 | 60µs | # spent 39µs (18+21) within Moose::Meta::Role::Composite::BEGIN@4 which was called:
# once (18µs+21µs) by Moose::BEGIN@33 at line 4 # spent 39µs making 1 call to Moose::Meta::Role::Composite::BEGIN@4
# spent 21µs making 1 call to strict::import |
5 | 2 | 27µs | 2 | 25µs | # spent 18µs (11+7) within Moose::Meta::Role::Composite::BEGIN@5 which was called:
# once (11µs+7µs) by Moose::BEGIN@33 at line 5 # spent 18µs making 1 call to Moose::Meta::Role::Composite::BEGIN@5
# spent 7µs making 1 call to warnings::import |
6 | 2 | 37µs | 2 | 1.40ms | # spent 703µs (11+692) within Moose::Meta::Role::Composite::BEGIN@6 which was called:
# once (11µs+692µs) by Moose::BEGIN@33 at line 6 # spent 703µs making 1 call to Moose::Meta::Role::Composite::BEGIN@6
# spent 692µs making 1 call to metaclass::import |
7 | |||||
8 | 2 | 33µs | 2 | 95µs | # spent 54µs (12+41) within Moose::Meta::Role::Composite::BEGIN@8 which was called:
# once (12µs+41µs) by Moose::BEGIN@33 at line 8 # spent 54µs making 1 call to Moose::Meta::Role::Composite::BEGIN@8
# spent 41µs making 1 call to Exporter::import |
9 | 2 | 38µs | 2 | 474µs | # spent 243µs (12+231) within Moose::Meta::Role::Composite::BEGIN@9 which was called:
# once (12µs+231µs) by Moose::BEGIN@33 at line 9 # spent 243µs making 1 call to Moose::Meta::Role::Composite::BEGIN@9
# spent 231µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337] |
10 | 2 | 942µs | 2 | 99µs | # spent 56µs (13+43) within Moose::Meta::Role::Composite::BEGIN@10 which was called:
# once (13µs+43µs) by Moose::BEGIN@33 at line 10 # spent 56µs making 1 call to Moose::Meta::Role::Composite::BEGIN@10
# spent 43µs making 1 call to parent::import |
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 | 1 | 7µs | 3 | 459µs | __PACKAGE__->meta->add_attribute('name' => ( # spent 429µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 22µs making 1 call to Moose::Meta::Role::Composite::meta
# spent 8µs making 1 call to Class::MOP::_definition_context |
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 | default => sub { {} }, | ||||
31 | 1 | 7µs | 3 | 363µs | Class::MOP::_definition_context(), # spent 345µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 12µs making 1 call to Moose::Meta::Role::Composite::meta
# spent 6µs making 1 call to Class::MOP::_definition_context |
32 | )); | ||||
33 | |||||
34 | __PACKAGE__->meta->add_attribute('_overloads' => ( | ||||
35 | reader => '_overload_map', | ||||
36 | default => sub { {} }, | ||||
37 | 1 | 6µs | 3 | 373µs | Class::MOP::_definition_context(), # spent 356µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 11µs making 1 call to Moose::Meta::Role::Composite::meta
# spent 6µs making 1 call to Class::MOP::_definition_context |
38 | )); | ||||
39 | |||||
40 | 1 | 5µs | 3 | 337µs | __PACKAGE__->meta->add_attribute('_overload_fallback' => ( # spent 320µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 12µs making 1 call to Moose::Meta::Role::Composite::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
41 | accessor => '_overload_fallback', | ||||
42 | Class::MOP::_definition_context(), | ||||
43 | )); | ||||
44 | |||||
45 | 1 | 5µs | 3 | 367µs | __PACKAGE__->meta->add_attribute( # spent 350µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 11µs making 1 call to Moose::Meta::Role::Composite::meta
# spent 6µs making 1 call to Class::MOP::_definition_context |
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 | sub new { | ||||
53 | my ($class, %params) = @_; | ||||
54 | |||||
55 | # the roles param is required ... | ||||
56 | foreach ( @{$params{roles}} ) { | ||||
57 | unless ( $_->isa('Moose::Meta::Role') ) { | ||||
58 | throw_exception( RolesListMustBeInstancesOfMooseMetaRole => params => \%params, | ||||
59 | role => $_, | ||||
60 | class => $class | ||||
61 | ); | ||||
62 | } | ||||
63 | } | ||||
64 | |||||
65 | my @composition_roles = map { | ||||
66 | $_->composition_class_roles | ||||
67 | } @{ $params{roles} }; | ||||
68 | |||||
69 | if (@composition_roles) { | ||||
70 | my $meta = Moose::Meta::Class->create_anon_class( | ||||
71 | superclasses => [ $class ], | ||||
72 | roles => [ @composition_roles ], | ||||
73 | cache => 1, | ||||
74 | ); | ||||
75 | $class = $meta->name; | ||||
76 | } | ||||
77 | |||||
78 | # and the name is created from the | ||||
79 | # roles if one has not been provided | ||||
80 | $params{name} ||= (join "|" => map { $_->name } @{$params{roles}}); | ||||
81 | $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 | sub is_anon { 0 } | ||||
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 | sub add_method { | ||||
95 | my ($self, $method_name, $method) = @_; | ||||
96 | |||||
97 | unless ( defined $method_name && $method_name ) { | ||||
98 | throw_exception( MustDefineAMethodName => instance => $self ); | ||||
99 | } | ||||
100 | |||||
101 | my $body; | ||||
102 | if (blessed($method)) { | ||||
103 | $body = $method->body; | ||||
104 | if ($method->package_name ne $self->name) { | ||||
105 | $method = $method->clone( | ||||
106 | package_name => $self->name, | ||||
107 | name => $method_name | ||||
108 | ) if $method->can('clone'); | ||||
109 | } | ||||
110 | } | ||||
111 | else { | ||||
112 | $body = $method; | ||||
113 | $method = $self->wrap_method_body( body => $body, name => $method_name ); | ||||
114 | } | ||||
115 | |||||
116 | $self->_method_map->{$method_name} = $method; | ||||
117 | } | ||||
118 | |||||
119 | sub get_method_list { | ||||
120 | my $self = shift; | ||||
121 | return keys %{ $self->_method_map }; | ||||
122 | } | ||||
123 | |||||
124 | sub _get_local_methods { | ||||
125 | my $self = shift; | ||||
126 | return values %{ $self->_method_map }; | ||||
127 | } | ||||
128 | |||||
129 | sub has_method { | ||||
130 | my ($self, $method_name) = @_; | ||||
131 | |||||
132 | return exists $self->_method_map->{$method_name}; | ||||
133 | } | ||||
134 | |||||
135 | sub get_method { | ||||
136 | my ($self, $method_name) = @_; | ||||
137 | |||||
138 | return $self->_method_map->{$method_name}; | ||||
139 | } | ||||
140 | |||||
141 | sub is_overloaded { | ||||
142 | my ($self) = @_; | ||||
143 | return keys %{ $self->_overload_map }; | ||||
144 | } | ||||
145 | |||||
146 | sub add_overloaded_operator { | ||||
147 | my ( $self, $op_name, $overload ) = @_; | ||||
148 | |||||
149 | unless ( defined $op_name && $op_name ) { | ||||
150 | throw_exception( | ||||
151 | 'MustDefineAnOverloadOperator', | ||||
152 | instance => $self, | ||||
153 | ); | ||||
154 | } | ||||
155 | |||||
156 | $self->_overload_map->{$op_name} = $overload; | ||||
157 | } | ||||
158 | |||||
159 | sub get_overload_fallback_value { | ||||
160 | my ($self) = @_; | ||||
161 | return $self->_overload_fallback; | ||||
162 | } | ||||
163 | |||||
164 | sub set_overload_fallback_value { | ||||
165 | my $self = shift; | ||||
166 | $self->_overload_fallback(shift); | ||||
167 | } | ||||
168 | |||||
169 | sub get_all_overloaded_operators { | ||||
170 | my ( $self, $method_name ) = @_; | ||||
171 | return values %{ $self->_overload_map }; | ||||
172 | } | ||||
173 | |||||
174 | sub apply_params { | ||||
175 | my ($self, $role_params) = @_; | ||||
176 | Moose::Util::_load_user_class($self->application_role_summation_class); | ||||
177 | |||||
178 | $self->application_role_summation_class->new( | ||||
179 | role_params => $role_params, | ||||
180 | )->apply($self); | ||||
181 | |||||
182 | return $self; | ||||
183 | } | ||||
184 | |||||
185 | sub reinitialize { | ||||
186 | my ( $class, $old_meta, @args ) = @_; | ||||
187 | |||||
188 | throw_exception( CannotInitializeMooseMetaRoleComposite => old_meta => $old_meta, | ||||
189 | args => \@args, | ||||
190 | role_composite => $class | ||||
191 | ) | ||||
192 | if !blessed $old_meta | ||||
193 | || !$old_meta->isa('Moose::Meta::Role::Composite'); | ||||
194 | |||||
195 | my %existing_classes = map { $_ => $old_meta->$_() } qw( | ||||
196 | application_role_summation_class | ||||
197 | ); | ||||
198 | |||||
199 | return $old_meta->meta->clone_object( $old_meta, %existing_classes, @args ); | ||||
200 | } | ||||
201 | |||||
202 | 1 | 21µs | 1; | ||
203 | |||||
204 | # ABSTRACT: An object to represent the set of roles | ||||
205 | |||||
206 | __END__ |