| Filename | /usr/local/lib/perl/5.10.1/Mouse/Meta/Class.pm |
| Statements | Executed 1067 statements in 6.23ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 45 | 1 | 1 | 1.67ms | 9.10ms | Mouse::Meta::Class::add_attribute |
| 16 | 1 | 1 | 208µs | 432µs | Mouse::Meta::Class::superclasses |
| 3 | 3 | 3 | 194µs | 304µs | Mouse::Meta::Class::_calculate_all_attributes |
| 5 | 5 | 5 | 179µs | 402µs | Mouse::Meta::Class::make_immutable |
| 8 | 1 | 1 | 135µs | 135µs | Mouse::Meta::Class::_construct_meta |
| 45 | 1 | 1 | 103µs | 103µs | Mouse::Meta::Class::_invalidate_metaclass_cache (xsub) |
| 3 | 1 | 1 | 68µs | 68µs | Mouse::Meta::Class::CORE:sort (opcode) |
| 45 | 1 | 1 | 65µs | 65µs | Mouse::Meta::Class::attribute_metaclass (xsub) |
| 8 | 1 | 1 | 65µs | 81µs | Mouse::Meta::Class::verify_superclass |
| 45 | 1 | 1 | 33µs | 33µs | Mouse::Meta::Class::CORE:subst (opcode) |
| 5 | 1 | 1 | 26µs | 26µs | Mouse::Meta::Class::immutable_options |
| 1 | 1 | 1 | 15µs | 65µs | Mouse::Meta::Class::BEGIN@2 |
| 1 | 1 | 1 | 9µs | 21µs | Mouse::Meta::Class::BEGIN@26 |
| 3 | 3 | 3 | 7µs | 7µs | Mouse::Meta::Class::strict_constructor (xsub) |
| 5 | 1 | 1 | 7µs | 7µs | Mouse::Meta::Class::constructor_class (xsub) |
| 3 | 1 | 1 | 7µs | 7µs | Mouse::Meta::Class::linearized_isa (xsub) |
| 1 | 1 | 1 | 6µs | 6µs | Mouse::Meta::Class::BEGIN@6 |
| 1 | 1 | 1 | 5µs | 5µs | Mouse::Meta::Class::BEGIN@4 |
| 3 | 1 | 1 | 4µs | 4µs | Mouse::Meta::Class::destructor_class (xsub) |
| 3 | 3 | 3 | 3µs | 3µs | Mouse::Meta::Class::is_immutable (xsub) |
| 3 | 3 | 3 | 3µs | 3µs | Mouse::Meta::Class::is_anon_class (xsub) |
| 0 | 0 | 0 | 0s | 0s | Mouse::Meta::Class::__ANON__[:356] |
| 0 | 0 | 0 | 0s | 0s | Mouse::Meta::Class::__ANON__[:381] |
| 0 | 0 | 0 | 0s | 0s | Mouse::Meta::Class::__ANON__[:419] |
| 0 | 0 | 0 | 0s | 0s | Mouse::Meta::Class::__ANON__[:439] |
| 0 | 0 | 0 | 0s | 0s | Mouse::Meta::Class::_collect_roles |
| 0 | 0 | 0 | 0s | 0s | Mouse::Meta::Class::_install_modifier |
| 0 | 0 | 0 | 0s | 0s | Mouse::Meta::Class::_reconcile_with_superclass_meta |
| 0 | 0 | 0 | 0s | 0s | Mouse::Meta::Class::add_after_method_modifier |
| 0 | 0 | 0 | 0s | 0s | Mouse::Meta::Class::add_around_method_modifier |
| 0 | 0 | 0 | 0s | 0s | Mouse::Meta::Class::add_augment_method_modifier |
| 0 | 0 | 0 | 0s | 0s | Mouse::Meta::Class::add_before_method_modifier |
| 0 | 0 | 0 | 0s | 0s | Mouse::Meta::Class::add_override_method_modifier |
| 0 | 0 | 0 | 0s | 0s | Mouse::Meta::Class::calculate_all_roles |
| 0 | 0 | 0 | 0s | 0s | Mouse::Meta::Class::create_anon_class |
| 0 | 0 | 0 | 0s | 0s | Mouse::Meta::Class::does_role |
| 0 | 0 | 0 | 0s | 0s | Mouse::Meta::Class::find_attribute_by_name |
| 0 | 0 | 0 | 0s | 0s | Mouse::Meta::Class::find_method_by_name |
| 0 | 0 | 0 | 0s | 0s | Mouse::Meta::Class::get_all_method_names |
| 0 | 0 | 0 | 0s | 0s | Mouse::Meta::Class::get_all_methods |
| 0 | 0 | 0 | 0s | 0s | Mouse::Meta::Class::inherit_from_foreign_class |
| 0 | 0 | 0 | 0s | 0s | Mouse::Meta::Class::is_mutable |
| 0 | 0 | 0 | 0s | 0s | Mouse::Meta::Class::make_mutable |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Mouse::Meta::Class; | ||||
| 2 | 3 | 34µs | 2 | 115µs | # spent 65µs (15+50) within Mouse::Meta::Class::BEGIN@2 which was called:
# once (15µs+50µs) by Mouse::BEGIN@14 at line 2 # spent 65µs making 1 call to Mouse::Meta::Class::BEGIN@2
# spent 50µs making 1 call to Mouse::Exporter::do_import |
| 3 | |||||
| 4 | 3 | 33µs | 1 | 5µs | # spent 5µs within Mouse::Meta::Class::BEGIN@4 which was called:
# once (5µs+0s) by Mouse::BEGIN@14 at line 4 # spent 5µs making 1 call to Mouse::Meta::Class::BEGIN@4 |
| 5 | |||||
| 6 | 3 | 131µs | 1 | 6µs | # spent 6µs within Mouse::Meta::Class::BEGIN@6 which was called:
# once (6µs+0s) by Mouse::BEGIN@14 at line 6 # spent 6µs making 1 call to Mouse::Meta::Class::BEGIN@6 |
| 7 | 1 | 16µs | our @ISA = qw(Mouse::Meta::Module); | ||
| 8 | |||||
| 9 | 1 | 900ns | our @CARP_NOT = qw(Mouse); # trust Mouse | ||
| 10 | |||||
| 11 | sub attribute_metaclass; | ||||
| 12 | sub method_metaclass; | ||||
| 13 | |||||
| 14 | sub constructor_class; | ||||
| 15 | sub destructor_class; | ||||
| 16 | |||||
| 17 | |||||
| 18 | # spent 135µs within Mouse::Meta::Class::_construct_meta which was called 8 times, avg 17µs/call:
# 8 times (135µs+0s) by Mouse::Meta::Module::initialize at line 23 of Mouse/Meta/Module.pm, avg 17µs/call | ||||
| 19 | 72 | 152µs | my($class, %args) = @_; | ||
| 20 | |||||
| 21 | $args{attributes} = {}; | ||||
| 22 | $args{methods} = {}; | ||||
| 23 | $args{roles} = []; | ||||
| 24 | |||||
| 25 | $args{superclasses} = do { | ||||
| 26 | 3 | 3.13ms | 2 | 34µs | # spent 21µs (9+12) within Mouse::Meta::Class::BEGIN@26 which was called:
# once (9µs+12µs) by Mouse::BEGIN@14 at line 26 # spent 21µs making 1 call to Mouse::Meta::Class::BEGIN@26
# spent 12µs making 1 call to strict::unimport |
| 27 | \@{ $args{package} . '::ISA' }; | ||||
| 28 | }; | ||||
| 29 | |||||
| 30 | my $self = bless \%args, ref($class) || $class; | ||||
| 31 | if(ref($self) ne __PACKAGE__){ | ||||
| 32 | $self->meta->_initialize_object($self, \%args); | ||||
| 33 | } | ||||
| 34 | return $self; | ||||
| 35 | } | ||||
| 36 | |||||
| 37 | sub create_anon_class{ | ||||
| 38 | my $self = shift; | ||||
| 39 | return $self->create(undef, @_); | ||||
| 40 | } | ||||
| 41 | |||||
| 42 | sub is_anon_class; | ||||
| 43 | |||||
| 44 | sub roles; | ||||
| 45 | |||||
| 46 | sub calculate_all_roles { | ||||
| 47 | my $self = shift; | ||||
| 48 | my %seen; | ||||
| 49 | return grep { !$seen{ $_->name }++ } | ||||
| 50 | map { $_->calculate_all_roles } @{ $self->roles }; | ||||
| 51 | } | ||||
| 52 | |||||
| 53 | # spent 432µs (208+224) within Mouse::Meta::Class::superclasses which was called 16 times, avg 27µs/call:
# 16 times (208µs+224µs) by Mouse::init_meta at line 139 of Mouse.pm, avg 27µs/call | ||||
| 54 | 80 | 203µs | my $self = shift; | ||
| 55 | |||||
| 56 | if (@_) { | ||||
| 57 | foreach my $super(@_){ | ||||
| 58 | 8 | 109µs | Mouse::Util::load_class($super); # spent 128µs making 8 calls to Mouse::Util::load_class, avg 16µs/call, recursion: max depth 1, sum of overlapping time 19µs | ||
| 59 | 8 | 15µs | my $meta = Mouse::Util::get_metaclass_by_name($super); # spent 15µs making 8 calls to Mouse::Meta::Module::_get_metaclass_by_name, avg 2µs/call | ||
| 60 | 8 | 81µs | next if $self->verify_superclass($super, $meta); # spent 81µs making 8 calls to Mouse::Meta::Class::verify_superclass, avg 10µs/call | ||
| 61 | $self->_reconcile_with_superclass_meta($meta); | ||||
| 62 | } | ||||
| 63 | return @{ $self->{superclasses} } = @_; | ||||
| 64 | } | ||||
| 65 | |||||
| 66 | return @{ $self->{superclasses} }; | ||||
| 67 | } | ||||
| 68 | |||||
| 69 | # spent 81µs (65+16) within Mouse::Meta::Class::verify_superclass which was called 8 times, avg 10µs/call:
# 8 times (65µs+16µs) by Mouse::Meta::Class::superclasses at line 60, avg 10µs/call | ||||
| 70 | 40 | 90µs | my($self, $super, $super_meta) = @_; | ||
| 71 | |||||
| 72 | if(defined $super_meta) { | ||||
| 73 | if(Mouse::Util::is_a_metarole($super_meta)){ | ||||
| 74 | $self->throw_error("You cannot inherit from a Mouse Role ($super)"); | ||||
| 75 | } | ||||
| 76 | } | ||||
| 77 | else { | ||||
| 78 | # The metaclass of $super is not initialized. | ||||
| 79 | # i.e. it might be Mouse::Object, a mixin package (e.g. Exporter), | ||||
| 80 | # or a foreign class including Moose classes. | ||||
| 81 | # See also Mouse::Foreign::Meta::Role::Class. | ||||
| 82 | 8 | 16µs | my $mm = $super->can('meta'); # spent 16µs making 8 calls to UNIVERSAL::can, avg 2µs/call | ||
| 83 | if(!($mm && $mm == \&Mouse::Util::meta)) { | ||||
| 84 | if($super->can('new') or $super->can('DESTROY')) { | ||||
| 85 | $self->inherit_from_foreign_class($super); | ||||
| 86 | } | ||||
| 87 | } | ||||
| 88 | return 1; # always ok | ||||
| 89 | } | ||||
| 90 | |||||
| 91 | return $self->isa(ref $super_meta); # checks metaclass compatibility | ||||
| 92 | } | ||||
| 93 | |||||
| 94 | sub inherit_from_foreign_class { | ||||
| 95 | my($class, $super) = @_; | ||||
| 96 | if($ENV{PERL_MOUSE_STRICT}) { | ||||
| 97 | Carp::carp("You inherit from non-Mouse class ($super)," | ||||
| 98 | . " but it is unlikely to work correctly." | ||||
| 99 | . " Please consider using MouseX::Foreign"); | ||||
| 100 | } | ||||
| 101 | return; | ||||
| 102 | } | ||||
| 103 | |||||
| 104 | 1 | 1µs | my @MetaClassTypes = ( | ||
| 105 | 'attribute', # Mouse::Meta::Attribute | ||||
| 106 | 'method', # Mouse::Meta::Method | ||||
| 107 | 'constructor', # Mouse::Meta::Method::Constructor | ||||
| 108 | 'destructor', # Mouse::Meta::Method::Destructor | ||||
| 109 | ); | ||||
| 110 | |||||
| 111 | sub _reconcile_with_superclass_meta { | ||||
| 112 | my($self, $other) = @_; | ||||
| 113 | |||||
| 114 | # find incompatible traits | ||||
| 115 | my %metaroles; | ||||
| 116 | foreach my $metaclass_type(@MetaClassTypes){ | ||||
| 117 | my $accessor = $self->can($metaclass_type . '_metaclass') | ||||
| 118 | || $self->can($metaclass_type . '_class'); | ||||
| 119 | |||||
| 120 | my $other_c = $other->$accessor(); | ||||
| 121 | my $self_c = $self->$accessor(); | ||||
| 122 | |||||
| 123 | if(!$self_c->isa($other_c)){ | ||||
| 124 | $metaroles{$metaclass_type} | ||||
| 125 | = [ $self_c->meta->_collect_roles($other_c->meta) ]; | ||||
| 126 | } | ||||
| 127 | } | ||||
| 128 | |||||
| 129 | $metaroles{class} = [$self->meta->_collect_roles($other->meta)]; | ||||
| 130 | |||||
| 131 | #use Data::Dumper; print Data::Dumper->new([\%metaroles], ['*metaroles'])->Indent(1)->Dump; | ||||
| 132 | |||||
| 133 | require Mouse::Util::MetaRole; | ||||
| 134 | $_[0] = Mouse::Util::MetaRole::apply_metaroles( | ||||
| 135 | for => $self, | ||||
| 136 | class_metaroles => \%metaroles, | ||||
| 137 | ); | ||||
| 138 | return; | ||||
| 139 | } | ||||
| 140 | |||||
| 141 | sub _collect_roles { | ||||
| 142 | my ($self, $other) = @_; | ||||
| 143 | |||||
| 144 | # find common ancestor | ||||
| 145 | my @self_lin_isa = $self->linearized_isa; | ||||
| 146 | my @other_lin_isa = $other->linearized_isa; | ||||
| 147 | |||||
| 148 | my(@self_anon_supers, @other_anon_supers); | ||||
| 149 | push @self_anon_supers, shift @self_lin_isa while $self_lin_isa[0]->meta->is_anon_class; | ||||
| 150 | push @other_anon_supers, shift @other_lin_isa while $other_lin_isa[0]->meta->is_anon_class; | ||||
| 151 | |||||
| 152 | my $common_ancestor = $self_lin_isa[0] eq $other_lin_isa[0] && $self_lin_isa[0]; | ||||
| 153 | |||||
| 154 | if(!$common_ancestor){ | ||||
| 155 | $self->throw_error(sprintf '%s cannot have %s as a super class because of their metaclass incompatibility', | ||||
| 156 | $self->name, $other->name); | ||||
| 157 | } | ||||
| 158 | |||||
| 159 | my %seen; | ||||
| 160 | return sort grep { !$seen{$_}++ } ## no critic | ||||
| 161 | (map{ $_->name } map{ $_->meta->calculate_all_roles } @self_anon_supers), | ||||
| 162 | (map{ $_->name } map{ $_->meta->calculate_all_roles } @other_anon_supers), | ||||
| 163 | ; | ||||
| 164 | } | ||||
| 165 | |||||
| 166 | |||||
| 167 | sub find_method_by_name { | ||||
| 168 | my($self, $method_name) = @_; | ||||
| 169 | defined($method_name) | ||||
| 170 | or $self->throw_error('You must define a method name to find'); | ||||
| 171 | |||||
| 172 | foreach my $class( $self->linearized_isa ){ | ||||
| 173 | my $method = $self->initialize($class)->get_method($method_name); | ||||
| 174 | return $method if defined $method; | ||||
| 175 | } | ||||
| 176 | return undef; | ||||
| 177 | } | ||||
| 178 | |||||
| 179 | sub get_all_methods { | ||||
| 180 | my($self) = @_; | ||||
| 181 | return map{ $self->find_method_by_name($_) } $self->get_all_method_names; | ||||
| 182 | } | ||||
| 183 | |||||
| 184 | sub get_all_method_names { | ||||
| 185 | my $self = shift; | ||||
| 186 | my %uniq; | ||||
| 187 | return grep { $uniq{$_}++ == 0 } | ||||
| 188 | map { Mouse::Meta::Class->initialize($_)->get_method_list() } | ||||
| 189 | $self->linearized_isa; | ||||
| 190 | } | ||||
| 191 | |||||
| 192 | sub find_attribute_by_name { | ||||
| 193 | my($self, $name) = @_; | ||||
| 194 | defined($name) | ||||
| 195 | or $self->throw_error('You must define an attribute name to find'); | ||||
| 196 | foreach my $attr($self->get_all_attributes) { | ||||
| 197 | return $attr if $attr->name eq $name; | ||||
| 198 | } | ||||
| 199 | return undef; | ||||
| 200 | } | ||||
| 201 | |||||
| 202 | # spent 9.10ms (1.67+7.43) within Mouse::Meta::Class::add_attribute which was called 45 times, avg 202µs/call:
# 45 times (1.67ms+7.43ms) by Mouse::has at line 52 of Mouse.pm, avg 202µs/call | ||||
| 203 | 765 | 1.87ms | my $self = shift; | ||
| 204 | |||||
| 205 | my($attr, $name); | ||||
| 206 | |||||
| 207 | 45 | 59µs | if(Scalar::Util::blessed($_[0])){ # spent 59µs making 45 calls to Scalar::Util::blessed, avg 1µs/call | ||
| 208 | $attr = $_[0]; | ||||
| 209 | |||||
| 210 | $attr->isa('Mouse::Meta::Attribute') | ||||
| 211 | || $self->throw_error("Your attribute must be an instance of Mouse::Meta::Attribute (or a subclass)"); | ||||
| 212 | |||||
| 213 | $name = $attr->name; | ||||
| 214 | } | ||||
| 215 | else{ | ||||
| 216 | # _process_attribute | ||||
| 217 | $name = shift; | ||||
| 218 | |||||
| 219 | my %args = (@_ == 1) ? %{$_[0]} : @_; | ||||
| 220 | |||||
| 221 | defined($name) | ||||
| 222 | or $self->throw_error('You must provide a name for the attribute'); | ||||
| 223 | |||||
| 224 | 45 | 33µs | if ($name =~ s/^\+//) { # inherited attributes # spent 33µs making 45 calls to Mouse::Meta::Class::CORE:subst, avg 744ns/call | ||
| 225 | my $inherited_attr = $self->find_attribute_by_name($name) | ||||
| 226 | or $self->throw_error("Could not find an attribute by the name of '$name' to inherit from in ".$self->name); | ||||
| 227 | |||||
| 228 | $attr = $inherited_attr->clone_and_inherit_options(%args); | ||||
| 229 | } | ||||
| 230 | else{ | ||||
| 231 | 90 | 243µs | my($attribute_class, @traits) = $self->attribute_metaclass->interpolate_class(\%args); # spent 178µs making 45 calls to Mouse::Meta::Attribute::interpolate_class, avg 4µs/call
# spent 65µs making 45 calls to Mouse::Meta::Class::attribute_metaclass, avg 1µs/call | ||
| 232 | $args{traits} = \@traits if @traits; | ||||
| 233 | |||||
| 234 | 45 | 2.29ms | $attr = $attribute_class->new($name, %args); # spent 2.29ms making 45 calls to Mouse::Meta::Attribute::new, avg 51µs/call | ||
| 235 | } | ||||
| 236 | } | ||||
| 237 | |||||
| 238 | 45 | 85µs | Scalar::Util::weaken( $attr->{associated_class} = $self ); # spent 85µs making 45 calls to Scalar::Util::weaken, avg 2µs/call | ||
| 239 | |||||
| 240 | # install accessors first | ||||
| 241 | 45 | 4.62ms | $attr->install_accessors(); # spent 4.62ms making 45 calls to Mouse::Meta::Attribute::install_accessors, avg 103µs/call | ||
| 242 | |||||
| 243 | # then register the attribute to the metaclass | ||||
| 244 | $attr->{insertion_order} = keys %{ $self->{attributes} }; | ||||
| 245 | $self->{attributes}{$name} = $attr; | ||||
| 246 | 45 | 103µs | $self->_invalidate_metaclass_cache(); # spent 103µs making 45 calls to Mouse::Meta::Class::_invalidate_metaclass_cache, avg 2µs/call | ||
| 247 | |||||
| 248 | if(!$attr->{associated_methods} && ($attr->{is} || '') ne 'bare'){ | ||||
| 249 | Carp::carp(qq{Attribute ($name) of class }.$self->name | ||||
| 250 | .qq{ has no associated methods (did you mean to provide an "is" argument?)}); | ||||
| 251 | } | ||||
| 252 | return $attr; | ||||
| 253 | } | ||||
| 254 | |||||
| 255 | # spent 304µs (194+110) within Mouse::Meta::Class::_calculate_all_attributes which was called 3 times, avg 101µs/call:
# once (118µs+76µs) by Mouse::Object::new at line 13 of mongo_pain.pl
# once (42µs+19µs) by Mouse::Object::new at line 531 of MongoDB/Connection.pm
# once (34µs+15µs) by Mouse::Object::new at line 108 of MongoDB/Database.pm | ||||
| 256 | 54 | 291µs | my($self) = @_; | ||
| 257 | my %seen; | ||||
| 258 | my @all_attrs; | ||||
| 259 | 3 | 7µs | foreach my $class($self->linearized_isa) { # spent 7µs making 3 calls to Mouse::Meta::Class::linearized_isa, avg 2µs/call | ||
| 260 | 6 | 12µs | my $meta = Mouse::Util::get_metaclass_by_name($class) or next; # spent 12µs making 6 calls to Mouse::Meta::Module::_get_metaclass_by_name, avg 2µs/call | ||
| 261 | 24 | 24µs | my @attrs = grep { !$seen{$_->name}++ } values %{$meta->{attributes}}; # spent 24µs making 24 calls to Mouse::Meta::Attribute::name, avg 979ns/call | ||
| 262 | @attrs = sort { | ||||
| 263 | 3 | 68µs | $b->{insertion_order} <=> $a->{insertion_order} # spent 68µs making 3 calls to Mouse::Meta::Class::CORE:sort, avg 22µs/call | ||
| 264 | } @attrs; | ||||
| 265 | push @all_attrs, @attrs; | ||||
| 266 | } | ||||
| 267 | return [reverse @all_attrs]; | ||||
| 268 | } | ||||
| 269 | |||||
| 270 | sub linearized_isa; | ||||
| 271 | |||||
| 272 | sub new_object; | ||||
| 273 | sub clone_object; | ||||
| 274 | |||||
| 275 | # spent 26µs within Mouse::Meta::Class::immutable_options which was called 5 times, avg 5µs/call:
# 5 times (26µs+0s) by Mouse::Meta::Class::make_immutable at line 288, avg 5µs/call | ||||
| 276 | 10 | 35µs | my ( $self, @args ) = @_; | ||
| 277 | |||||
| 278 | return ( | ||||
| 279 | inline_constructor => 1, | ||||
| 280 | inline_destructor => 1, | ||||
| 281 | constructor_name => 'new', | ||||
| 282 | @args, | ||||
| 283 | ); | ||||
| 284 | } | ||||
| 285 | |||||
| 286 | # spent 402µs (179+223) within Mouse::Meta::Class::make_immutable which was called 5 times, avg 80µs/call:
# once (56µs+62µs) by MongoDB::Connection::BEGIN@2 at line 329 of MongoDB/Database.pm
# once (34µs+49µs) by Mouse::Util::_try_load_one_class at line 724 of MongoDB/Collection.pm
# once (31µs+47µs) by MongoDB::Connection::BEGIN@2.4 at line 144 of MongoDB/OID.pm
# once (35µs+31µs) by MongoDB::Connection::BEGIN@23 at line 488 of MongoDB/Cursor.pm
# once (23µs+33µs) by MongoDB::BEGIN@26 at line 738 of MongoDB/Connection.pm | ||||
| 287 | 30 | 235µs | my $self = shift; | ||
| 288 | 5 | 26µs | my %args = $self->immutable_options(@_); # spent 26µs making 5 calls to Mouse::Meta::Class::immutable_options, avg 5µs/call | ||
| 289 | |||||
| 290 | $self->{is_immutable}++; | ||||
| 291 | |||||
| 292 | 20 | 115µs | if ($args{inline_constructor}) { # spent 88µs making 5 calls to Mouse::Util::load_class, avg 18µs/call, recursion: max depth 1, sum of overlapping time 16µs
# spent 30µs making 5 calls to Mouse::Meta::Module::add_method, avg 6µs/call
# spent 7µs making 5 calls to Mouse::Meta::Class::constructor_class, avg 1µs/call
# spent 6µs making 5 calls to Mouse::Meta::Method::Constructor::XS::_generate_constructor, avg 1µs/call | ||
| 293 | $self->add_method($args{constructor_name} => | ||||
| 294 | Mouse::Util::load_class($self->constructor_class) | ||||
| 295 | ->_generate_constructor($self, \%args)); | ||||
| 296 | } | ||||
| 297 | |||||
| 298 | 12 | 52µs | if ($args{inline_destructor}) { # spent 44µs making 3 calls to Mouse::Util::load_class, avg 15µs/call, recursion: max depth 1, sum of overlapping time 14µs
# spent 16µs making 3 calls to Mouse::Meta::Module::add_method, avg 5µs/call
# spent 4µs making 3 calls to Mouse::Meta::Class::destructor_class, avg 1µs/call
# spent 3µs making 3 calls to Mouse::Meta::Method::Destructor::XS::_generate_destructor, avg 1µs/call | ||
| 299 | $self->add_method(DESTROY => | ||||
| 300 | Mouse::Util::load_class($self->destructor_class) | ||||
| 301 | ->_generate_destructor($self, \%args)); | ||||
| 302 | } | ||||
| 303 | |||||
| 304 | # Moose's make_immutable returns true allowing calling code to skip | ||||
| 305 | # setting an explicit true value at the end of a source file. | ||||
| 306 | return 1; | ||||
| 307 | } | ||||
| 308 | |||||
| 309 | sub make_mutable { | ||||
| 310 | my($self) = @_; | ||||
| 311 | $self->{is_immutable} = 0; | ||||
| 312 | return; | ||||
| 313 | } | ||||
| 314 | |||||
| 315 | sub is_immutable; | ||||
| 316 | sub is_mutable { !$_[0]->is_immutable } | ||||
| 317 | |||||
| 318 | sub _install_modifier { | ||||
| 319 | my( $self, $type, $name, $code ) = @_; | ||||
| 320 | my $into = $self->name; | ||||
| 321 | |||||
| 322 | my $original = $into->can($name) | ||||
| 323 | or $self->throw_error("The method '$name' was not found in the inheritance hierarchy for $into"); | ||||
| 324 | |||||
| 325 | my $modifier_table = $self->{modifiers}{$name}; | ||||
| 326 | |||||
| 327 | if(!$modifier_table){ | ||||
| 328 | my(@before, @after, @around); | ||||
| 329 | my $cache = $original; | ||||
| 330 | my $modified = sub { | ||||
| 331 | if(@before) { | ||||
| 332 | for my $c (@before) { $c->(@_) } | ||||
| 333 | } | ||||
| 334 | unless(@after) { | ||||
| 335 | return $cache->(@_); | ||||
| 336 | } | ||||
| 337 | |||||
| 338 | if(wantarray){ # list context | ||||
| 339 | my @rval = $cache->(@_); | ||||
| 340 | |||||
| 341 | for my $c(@after){ $c->(@_) } | ||||
| 342 | return @rval; | ||||
| 343 | } | ||||
| 344 | elsif(defined wantarray){ # scalar context | ||||
| 345 | my $rval = $cache->(@_); | ||||
| 346 | |||||
| 347 | for my $c(@after){ $c->(@_) } | ||||
| 348 | return $rval; | ||||
| 349 | } | ||||
| 350 | else{ # void context | ||||
| 351 | $cache->(@_); | ||||
| 352 | |||||
| 353 | for my $c(@after){ $c->(@_) } | ||||
| 354 | return; | ||||
| 355 | } | ||||
| 356 | }; | ||||
| 357 | |||||
| 358 | $self->{modifiers}{$name} = $modifier_table = { | ||||
| 359 | original => $original, | ||||
| 360 | |||||
| 361 | before => \@before, | ||||
| 362 | after => \@after, | ||||
| 363 | around => \@around, | ||||
| 364 | |||||
| 365 | cache => \$cache, # cache for around modifiers | ||||
| 366 | }; | ||||
| 367 | |||||
| 368 | $self->add_method($name => $modified); | ||||
| 369 | } | ||||
| 370 | |||||
| 371 | if($type eq 'before'){ | ||||
| 372 | unshift @{$modifier_table->{before}}, $code; | ||||
| 373 | } | ||||
| 374 | elsif($type eq 'after'){ | ||||
| 375 | push @{$modifier_table->{after}}, $code; | ||||
| 376 | } | ||||
| 377 | else{ # around | ||||
| 378 | push @{$modifier_table->{around}}, $code; | ||||
| 379 | |||||
| 380 | my $next = ${ $modifier_table->{cache} }; | ||||
| 381 | ${ $modifier_table->{cache} } = sub{ $code->($next, @_) }; | ||||
| 382 | } | ||||
| 383 | |||||
| 384 | return; | ||||
| 385 | } | ||||
| 386 | |||||
| 387 | sub add_before_method_modifier { | ||||
| 388 | my ( $self, $name, $code ) = @_; | ||||
| 389 | $self->_install_modifier( 'before', $name, $code ); | ||||
| 390 | } | ||||
| 391 | |||||
| 392 | sub add_around_method_modifier { | ||||
| 393 | my ( $self, $name, $code ) = @_; | ||||
| 394 | $self->_install_modifier( 'around', $name, $code ); | ||||
| 395 | } | ||||
| 396 | |||||
| 397 | sub add_after_method_modifier { | ||||
| 398 | my ( $self, $name, $code ) = @_; | ||||
| 399 | $self->_install_modifier( 'after', $name, $code ); | ||||
| 400 | } | ||||
| 401 | |||||
| 402 | sub add_override_method_modifier { | ||||
| 403 | my ($self, $name, $code) = @_; | ||||
| 404 | |||||
| 405 | if($self->has_method($name)){ | ||||
| 406 | $self->throw_error("Cannot add an override method if a local method is already present"); | ||||
| 407 | } | ||||
| 408 | |||||
| 409 | my $package = $self->name; | ||||
| 410 | |||||
| 411 | my $super_body = $package->can($name) | ||||
| 412 | or $self->throw_error("You cannot override '$name' because it has no super method"); | ||||
| 413 | |||||
| 414 | $self->add_method($name => sub { | ||||
| 415 | local $Mouse::SUPER_PACKAGE = $package; | ||||
| 416 | local $Mouse::SUPER_BODY = $super_body; | ||||
| 417 | local @Mouse::SUPER_ARGS = @_; | ||||
| 418 | &{$code}; | ||||
| 419 | }); | ||||
| 420 | return; | ||||
| 421 | } | ||||
| 422 | |||||
| 423 | sub add_augment_method_modifier { | ||||
| 424 | my ($self, $name, $code) = @_; | ||||
| 425 | if($self->has_method($name)){ | ||||
| 426 | $self->throw_error("Cannot add an augment method if a local method is already present"); | ||||
| 427 | } | ||||
| 428 | |||||
| 429 | my $super = $self->find_method_by_name($name) | ||||
| 430 | or $self->throw_error("You cannot augment '$name' because it has no super method"); | ||||
| 431 | |||||
| 432 | my $super_package = $super->package_name; | ||||
| 433 | my $super_body = $super->body; | ||||
| 434 | |||||
| 435 | $self->add_method($name => sub { | ||||
| 436 | local $Mouse::INNER_BODY{$super_package} = $code; | ||||
| 437 | local $Mouse::INNER_ARGS{$super_package} = [@_]; | ||||
| 438 | &{$super_body}; | ||||
| 439 | }); | ||||
| 440 | return; | ||||
| 441 | } | ||||
| 442 | |||||
| 443 | sub does_role { | ||||
| 444 | my ($self, $role_name) = @_; | ||||
| 445 | |||||
| 446 | (defined $role_name) | ||||
| 447 | || $self->throw_error("You must supply a role name to look for"); | ||||
| 448 | |||||
| 449 | $role_name = $role_name->name if ref $role_name; | ||||
| 450 | |||||
| 451 | for my $class ($self->linearized_isa) { | ||||
| 452 | my $meta = Mouse::Util::get_metaclass_by_name($class) | ||||
| 453 | or next; | ||||
| 454 | |||||
| 455 | for my $role (@{ $meta->roles }) { | ||||
| 456 | |||||
| 457 | return 1 if $role->does_role($role_name); | ||||
| 458 | } | ||||
| 459 | } | ||||
| 460 | |||||
| 461 | return 0; | ||||
| 462 | } | ||||
| 463 | |||||
| 464 | 1 | 6µs | 1; | ||
| 465 | __END__ | ||||
# spent 68µs within Mouse::Meta::Class::CORE:sort which was called 3 times, avg 22µs/call:
# 3 times (68µs+0s) by Mouse::Meta::Class::_calculate_all_attributes at line 263, avg 22µs/call | |||||
# spent 33µs within Mouse::Meta::Class::CORE:subst which was called 45 times, avg 744ns/call:
# 45 times (33µs+0s) by Mouse::Meta::Class::add_attribute at line 224, avg 744ns/call | |||||
# spent 103µs within Mouse::Meta::Class::_invalidate_metaclass_cache which was called 45 times, avg 2µs/call:
# 45 times (103µs+0s) by Mouse::Meta::Class::add_attribute at line 246, avg 2µs/call | |||||
# spent 65µs within Mouse::Meta::Class::attribute_metaclass which was called 45 times, avg 1µs/call:
# 45 times (65µs+0s) by Mouse::Meta::Class::add_attribute at line 231, avg 1µs/call | |||||
# spent 7µs within Mouse::Meta::Class::constructor_class which was called 5 times, avg 1µs/call:
# 5 times (7µs+0s) by Mouse::Meta::Class::make_immutable at line 292, avg 1µs/call | |||||
# spent 4µs within Mouse::Meta::Class::destructor_class which was called 3 times, avg 1µs/call:
# 3 times (4µs+0s) by Mouse::Meta::Class::make_immutable at line 298, avg 1µs/call | |||||
# spent 3µs within Mouse::Meta::Class::is_anon_class which was called 3 times, avg 1µs/call:
# once (1µs+0s) by Mouse::Object::new at line 531 of MongoDB/Connection.pm
# once (1µs+0s) by Mouse::Object::new at line 13 of mongo_pain.pl
# once (900ns+0s) by Mouse::Object::new at line 108 of MongoDB/Database.pm | |||||
# spent 3µs within Mouse::Meta::Class::is_immutable which was called 3 times, avg 1µs/call:
# once (1µs+0s) by Mouse::Object::new at line 531 of MongoDB/Connection.pm
# once (1µs+0s) by Mouse::Object::new at line 13 of mongo_pain.pl
# once (1µs+0s) by Mouse::Object::new at line 108 of MongoDB/Database.pm | |||||
# spent 7µs within Mouse::Meta::Class::linearized_isa which was called 3 times, avg 2µs/call:
# 3 times (7µs+0s) by Mouse::Meta::Class::_calculate_all_attributes at line 259, avg 2µs/call | |||||
# spent 7µs within Mouse::Meta::Class::strict_constructor which was called 3 times, avg 2µs/call:
# once (2µs+0s) by Mouse::Object::new at line 531 of MongoDB/Connection.pm
# once (2µs+0s) by Mouse::Object::new at line 13 of mongo_pain.pl
# once (2µs+0s) by Mouse::Object::new at line 108 of MongoDB/Database.pm |