| Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/Role/Composite.pm |
| Statements | Executed 25 statements in 730µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 10µs | 10µs | Moose::Meta::Role::Composite::BEGIN@2 |
| 1 | 1 | 1 | 9µs | 49µs | Moose::Meta::Role::Composite::BEGIN@13 |
| 1 | 1 | 1 | 9µs | 14µs | Moose::Meta::Role::Composite::BEGIN@9 |
| 1 | 1 | 1 | 8µs | 96µs | Moose::Meta::Role::Composite::BEGIN@16 |
| 1 | 1 | 1 | 8µs | 681µs | Moose::Meta::Role::Composite::BEGIN@11 |
| 1 | 1 | 1 | 8µs | 25µs | Moose::Meta::Role::Composite::BEGIN@10 |
| 1 | 1 | 1 | 7µs | 30µs | Moose::Meta::Role::Composite::BEGIN@14 |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Composite::__ANON__[:36] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Composite::_get_local_methods |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Composite::add_method |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Composite::apply_params |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Composite::get_method |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Composite::get_method_list |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Composite::has_method |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Composite::new |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Composite::reinitialize |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Moose::Meta::Role::Composite; | ||||
| 2 | # spent 10µs within Moose::Meta::Role::Composite::BEGIN@2 which was called:
# once (10µs+0s) by Moose::BEGIN@37 at line 4 | ||||
| 3 | 1 | 5µs | $Moose::Meta::Role::Composite::AUTHORITY = 'cpan:STEVAN'; | ||
| 4 | 1 | 24µs | 1 | 10µs | } # spent 10µs making 1 call to Moose::Meta::Role::Composite::BEGIN@2 |
| 5 | { | ||||
| 6 | 2 | 1µs | $Moose::Meta::Role::Composite::VERSION = '2.0602'; | ||
| 7 | } | ||||
| 8 | |||||
| 9 | 3 | 20µs | 2 | 19µs | # spent 14µs (9+5) within Moose::Meta::Role::Composite::BEGIN@9 which was called:
# once (9µs+5µs) by Moose::BEGIN@37 at line 9 # spent 14µs making 1 call to Moose::Meta::Role::Composite::BEGIN@9
# spent 5µs making 1 call to strict::import |
| 10 | 3 | 19µs | 2 | 43µs | # spent 25µs (8+18) within Moose::Meta::Role::Composite::BEGIN@10 which was called:
# once (8µs+18µs) by Moose::BEGIN@37 at line 10 # spent 25µs making 1 call to Moose::Meta::Role::Composite::BEGIN@10
# spent 18µs making 1 call to warnings::import |
| 11 | 3 | 30µs | 2 | 1.35ms | # spent 681µs (8+673) within Moose::Meta::Role::Composite::BEGIN@11 which was called:
# once (8µs+673µs) by Moose::BEGIN@37 at line 11 # spent 681µs making 1 call to Moose::Meta::Role::Composite::BEGIN@11
# spent 673µs making 1 call to metaclass::import |
| 12 | |||||
| 13 | 3 | 22µs | 2 | 88µs | # spent 49µs (9+40) within Moose::Meta::Role::Composite::BEGIN@13 which was called:
# once (9µs+40µs) by Moose::BEGIN@37 at line 13 # spent 49µs making 1 call to Moose::Meta::Role::Composite::BEGIN@13
# spent 40µs making 1 call to Exporter::import |
| 14 | 3 | 20µs | 2 | 53µs | # spent 30µs (7+23) within Moose::Meta::Role::Composite::BEGIN@14 which was called:
# once (7µs+23µs) by Moose::BEGIN@37 at line 14 # spent 30µs making 1 call to Moose::Meta::Role::Composite::BEGIN@14
# spent 23µs making 1 call to Exporter::import |
| 15 | |||||
| 16 | 3 | 563µs | 2 | 184µs | # spent 96µs (8+88) within Moose::Meta::Role::Composite::BEGIN@16 which was called:
# once (8µs+88µs) by Moose::BEGIN@37 at line 16 # spent 96µs making 1 call to Moose::Meta::Role::Composite::BEGIN@16
# spent 88µ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 | 6µs | 3 | 471µs | __PACKAGE__->meta->add_attribute('name' => ( # spent 441µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 20µs making 1 call to Moose::Meta::Role::Composite::meta
# spent 9µ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 | 5µs | 3 | 308µs | Class::MOP::_definition_context(), # spent 291µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 11µs making 1 call to Moose::Meta::Role::Composite::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
| 38 | )); | ||||
| 39 | |||||
| 40 | 1 | 4µs | 3 | 276µs | __PACKAGE__->meta->add_attribute( # spent 261µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 10µs making 1 call to Moose::Meta::Role::Composite::meta
# spent 5µ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 to which which | ||||
| 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 | 11µs | 1; | ||
| 156 | |||||
| 157 | # ABSTRACT: An object to represent the set of roles | ||||
| 158 | |||||
| - - | |||||
| 161 | =pod | ||||
| 162 | |||||
| 163 | =head1 NAME | ||||
| 164 | |||||
| 165 | Moose::Meta::Role::Composite - An object to represent the set of roles | ||||
| 166 | |||||
| 167 | =head1 VERSION | ||||
| 168 | |||||
| 169 | version 2.0602 | ||||
| 170 | |||||
| 171 | =head1 DESCRIPTION | ||||
| 172 | |||||
| 173 | A composite is a role that consists of a set of two or more roles. | ||||
| 174 | |||||
| 175 | The API of a composite role is almost identical to that of a regular | ||||
| 176 | role. | ||||
| 177 | |||||
| 178 | =head1 INHERITANCE | ||||
| 179 | |||||
| 180 | C<Moose::Meta::Role::Composite> is a subclass of L<Moose::Meta::Role>. | ||||
| 181 | |||||
| 182 | =head2 METHODS | ||||
| 183 | |||||
| 184 | =over 4 | ||||
| 185 | |||||
| 186 | =item B<< Moose::Meta::Role::Composite->new(%options) >> | ||||
| 187 | |||||
| 188 | This returns a new composite role object. It accepts the same | ||||
| 189 | options as its parent class, with a few changes: | ||||
| 190 | |||||
| 191 | =over 8 | ||||
| 192 | |||||
| 193 | =item * roles | ||||
| 194 | |||||
| 195 | This option is an array reference containing a list of | ||||
| 196 | L<Moose::Meta::Role> object. This is a required option. | ||||
| 197 | |||||
| 198 | =item * name | ||||
| 199 | |||||
| 200 | If a name is not given, one is generated from the roles provided. | ||||
| 201 | |||||
| 202 | =item * apply_params(\%role_params) | ||||
| 203 | |||||
| 204 | Creates a new RoleSummation role application with C<%role_params> and applies | ||||
| 205 | the composite role to it. The RoleSummation role application class used is | ||||
| 206 | determined by the composite role's C<application_role_summation_class> | ||||
| 207 | attribute. | ||||
| 208 | |||||
| 209 | =item * reinitialize($metaclass) | ||||
| 210 | |||||
| 211 | Like C<< Class::MOP::Package->reinitialize >>, but doesn't allow passing a | ||||
| 212 | string with the package name, as there is no real package for composite roles. | ||||
| 213 | |||||
| 214 | =back | ||||
| 215 | |||||
| 216 | =back | ||||
| 217 | |||||
| 218 | =head1 BUGS | ||||
| 219 | |||||
| 220 | See L<Moose/BUGS> for details on reporting bugs. | ||||
| 221 | |||||
| 222 | =head1 AUTHOR | ||||
| 223 | |||||
| 224 | Moose is maintained by the Moose Cabal, along with the help of many contributors. See L<Moose/CABAL> and L<Moose/CONTRIBUTORS> for details. | ||||
| 225 | |||||
| 226 | =head1 COPYRIGHT AND LICENSE | ||||
| 227 | |||||
| 228 | This software is copyright (c) 2012 by Infinity Interactive, Inc.. | ||||
| 229 | |||||
| 230 | This is free software; you can redistribute it and/or modify it under | ||||
| 231 | the same terms as the Perl 5 programming language system itself. | ||||
| 232 | |||||
| 233 | =cut | ||||
| 234 | |||||
| 235 | |||||
| 236 | __END__ |