Filename | /opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Meta/Role/Composite.pm |
Statements | Executed 19 statements in 1.03ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 12µs | 12µs | BEGIN@2 | Moose::Meta::Role::Composite::
1 | 1 | 1 | 10µs | 38µs | BEGIN@14 | Moose::Meta::Role::Composite::
1 | 1 | 1 | 9µs | 43µs | BEGIN@13 | Moose::Meta::Role::Composite::
1 | 1 | 1 | 9µs | 14µs | BEGIN@10 | Moose::Meta::Role::Composite::
1 | 1 | 1 | 9µs | 81µs | BEGIN@16 | Moose::Meta::Role::Composite::
1 | 1 | 1 | 8µs | 490µs | BEGIN@11 | Moose::Meta::Role::Composite::
1 | 1 | 1 | 8µs | 24µs | BEGIN@9 | 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 | apply_params | 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 | has_method | Moose::Meta::Role::Composite::
0 | 0 | 0 | 0s | 0s | new | Moose::Meta::Role::Composite::
0 | 0 | 0 | 0s | 0s | reinitialize | Moose::Meta::Role::Composite::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Moose::Meta::Role::Composite; | ||||
2 | # spent 12µs within Moose::Meta::Role::Composite::BEGIN@2 which was called:
# once (12µs+0s) by Moose::BEGIN@36 at line 4 | ||||
3 | 1 | 6µs | $Moose::Meta::Role::Composite::AUTHORITY = 'cpan:STEVAN'; | ||
4 | 1 | 44µs | 1 | 12µs | } # spent 12µs making 1 call to Moose::Meta::Role::Composite::BEGIN@2 |
5 | { | ||||
6 | 2 | 1µs | $Moose::Meta::Role::Composite::VERSION = '2.1005'; | ||
7 | } | ||||
8 | |||||
9 | 2 | 31µs | 2 | 40µs | # spent 24µs (8+16) within Moose::Meta::Role::Composite::BEGIN@9 which was called:
# once (8µs+16µs) by Moose::BEGIN@36 at line 9 # spent 24µs making 1 call to Moose::Meta::Role::Composite::BEGIN@9
# spent 16µs making 1 call to strict::import |
10 | 2 | 28µs | 2 | 20µs | # spent 14µs (9+5) within Moose::Meta::Role::Composite::BEGIN@10 which was called:
# once (9µs+5µs) by Moose::BEGIN@36 at line 10 # spent 14µs making 1 call to Moose::Meta::Role::Composite::BEGIN@10
# spent 5µs making 1 call to warnings::import |
11 | 2 | 46µs | 2 | 971µs | # spent 490µs (8+481) within Moose::Meta::Role::Composite::BEGIN@11 which was called:
# once (8µs+481µs) by Moose::BEGIN@36 at line 11 # spent 490µs making 1 call to Moose::Meta::Role::Composite::BEGIN@11
# spent 481µs making 1 call to metaclass::import |
12 | |||||
13 | 2 | 39µs | 2 | 76µs | # spent 43µs (9+33) within Moose::Meta::Role::Composite::BEGIN@13 which was called:
# once (9µs+33µs) by Moose::BEGIN@36 at line 13 # spent 43µs making 1 call to Moose::Meta::Role::Composite::BEGIN@13
# spent 33µs making 1 call to Exporter::import |
14 | 2 | 35µs | 2 | 66µs | # spent 38µs (10+28) within Moose::Meta::Role::Composite::BEGIN@14 which was called:
# once (10µs+28µs) by Moose::BEGIN@36 at line 14 # spent 38µs making 1 call to Moose::Meta::Role::Composite::BEGIN@14
# spent 28µs making 1 call to Exporter::import |
15 | |||||
16 | 2 | 778µs | 2 | 153µs | # spent 81µs (9+72) within Moose::Meta::Role::Composite::BEGIN@16 which was called:
# once (9µs+72µs) by Moose::BEGIN@36 at line 16 # spent 81µs making 1 call to Moose::Meta::Role::Composite::BEGIN@16
# spent 72µs making 1 call to base::import |
17 | |||||
18 | # NOTE: | ||||
19 | # we need to override the ->name | ||||
20 | # method from Class::MOP::Package | ||||
21 | # since we don't have an actual | ||||
22 | # package for this. | ||||
23 | # - SL | ||||
24 | 1 | 5µs | 3 | 422µs | __PACKAGE__->meta->add_attribute('name' => ( # spent 390µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 26µs making 1 call to Moose::Meta::Role::Composite::meta
# spent 7µs making 1 call to Class::MOP::_definition_context |
25 | reader => 'name', | ||||
26 | Class::MOP::_definition_context(), | ||||
27 | )); | ||||
28 | |||||
29 | # NOTE: | ||||
30 | # Again, since we don't have a real | ||||
31 | # package to store our methods in, | ||||
32 | # we use a HASH ref instead. | ||||
33 | # - SL | ||||
34 | __PACKAGE__->meta->add_attribute('_methods' => ( | ||||
35 | reader => '_method_map', | ||||
36 | default => sub { {} }, | ||||
37 | 1 | 6µs | 3 | 410µs | Class::MOP::_definition_context(), # spent 391µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 12µs making 1 call to Moose::Meta::Role::Composite::meta
# spent 7µs making 1 call to Class::MOP::_definition_context |
38 | )); | ||||
39 | |||||
40 | 1 | 4µs | 3 | 409µs | __PACKAGE__->meta->add_attribute( # spent 386µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 16µs making 1 call to Moose::Meta::Role::Composite::meta
# spent 7µs making 1 call to Class::MOP::_definition_context |
41 | 'application_role_summation_class', | ||||
42 | reader => 'application_role_summation_class', | ||||
43 | default => 'Moose::Meta::Role::Application::RoleSummation', | ||||
44 | Class::MOP::_definition_context(), | ||||
45 | ); | ||||
46 | |||||
47 | sub new { | ||||
48 | my ($class, %params) = @_; | ||||
49 | |||||
50 | # the roles param is required ... | ||||
51 | foreach ( @{$params{roles}} ) { | ||||
52 | unless ( $_->isa('Moose::Meta::Role') ) { | ||||
53 | require Moose; | ||||
54 | Moose->throw_error("The list of roles must be instances of Moose::Meta::Role, not $_"); | ||||
55 | } | ||||
56 | } | ||||
57 | |||||
58 | my @composition_roles = map { | ||||
59 | $_->composition_class_roles | ||||
60 | } @{ $params{roles} }; | ||||
61 | |||||
62 | if (@composition_roles) { | ||||
63 | my $meta = Moose::Meta::Class->create_anon_class( | ||||
64 | superclasses => [ $class ], | ||||
65 | roles => [ @composition_roles ], | ||||
66 | cache => 1, | ||||
67 | ); | ||||
68 | $class = $meta->name; | ||||
69 | } | ||||
70 | |||||
71 | # and the name is created from the | ||||
72 | # roles if one has not been provided | ||||
73 | $params{name} ||= (join "|" => map { $_->name } @{$params{roles}}); | ||||
74 | $class->_new(\%params); | ||||
75 | } | ||||
76 | |||||
77 | # This is largely a copy of what's in Moose::Meta::Role (itself | ||||
78 | # largely a copy of Class::MOP::Class). However, we can't actually | ||||
79 | # call add_package_symbol, because there's no package into which to | ||||
80 | # add the symbol. | ||||
81 | sub add_method { | ||||
82 | my ($self, $method_name, $method) = @_; | ||||
83 | |||||
84 | unless ( defined $method_name && $method_name ) { | ||||
85 | Moose->throw_error("You must define a method name"); | ||||
86 | } | ||||
87 | |||||
88 | my $body; | ||||
89 | if (blessed($method)) { | ||||
90 | $body = $method->body; | ||||
91 | if ($method->package_name ne $self->name) { | ||||
92 | $method = $method->clone( | ||||
93 | package_name => $self->name, | ||||
94 | name => $method_name | ||||
95 | ) if $method->can('clone'); | ||||
96 | } | ||||
97 | } | ||||
98 | else { | ||||
99 | $body = $method; | ||||
100 | $method = $self->wrap_method_body( body => $body, name => $method_name ); | ||||
101 | } | ||||
102 | |||||
103 | $self->_method_map->{$method_name} = $method; | ||||
104 | } | ||||
105 | |||||
106 | sub get_method_list { | ||||
107 | my $self = shift; | ||||
108 | return keys %{ $self->_method_map }; | ||||
109 | } | ||||
110 | |||||
111 | sub _get_local_methods { | ||||
112 | my $self = shift; | ||||
113 | return values %{ $self->_method_map }; | ||||
114 | } | ||||
115 | |||||
116 | sub has_method { | ||||
117 | my ($self, $method_name) = @_; | ||||
118 | |||||
119 | return exists $self->_method_map->{$method_name}; | ||||
120 | } | ||||
121 | |||||
122 | sub get_method { | ||||
123 | my ($self, $method_name) = @_; | ||||
124 | |||||
125 | return $self->_method_map->{$method_name}; | ||||
126 | } | ||||
127 | |||||
128 | sub apply_params { | ||||
129 | my ($self, $role_params) = @_; | ||||
130 | load_class($self->application_role_summation_class); | ||||
131 | |||||
132 | $self->application_role_summation_class->new( | ||||
133 | role_params => $role_params, | ||||
134 | )->apply($self); | ||||
135 | |||||
136 | return $self; | ||||
137 | } | ||||
138 | |||||
139 | sub reinitialize { | ||||
140 | my ( $class, $old_meta, @args ) = @_; | ||||
141 | |||||
142 | Moose->throw_error( | ||||
143 | 'Moose::Meta::Role::Composite instances can only be reinitialized from an existing metaclass instance' | ||||
144 | ) | ||||
145 | if !blessed $old_meta | ||||
146 | || !$old_meta->isa('Moose::Meta::Role::Composite'); | ||||
147 | |||||
148 | my %existing_classes = map { $_ => $old_meta->$_() } qw( | ||||
149 | application_role_summation_class | ||||
150 | ); | ||||
151 | |||||
152 | return $old_meta->meta->clone_object( $old_meta, %existing_classes, @args ); | ||||
153 | } | ||||
154 | |||||
155 | 1 | 10µs | 1; | ||
156 | |||||
157 | # ABSTRACT: An object to represent the set of roles | ||||
158 | |||||
159 | __END__ |