| Filename | /Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Class/MOP/Object.pm |
| Statements | Executed 2453 statements in 3.49ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 526 | 3 | 2 | 1.32ms | 1.77ms | Class::MOP::Object::_is_compatible_with |
| 398 | 2 | 1 | 988µs | 2.34ms | Class::MOP::Object::_can_be_made_compatible_with |
| 1 | 1 | 1 | 8µs | 193µs | Class::MOP::Object::_new |
| 1 | 1 | 1 | 8µs | 24µs | Class::MOP::Object::BEGIN@14 |
| 1 | 1 | 1 | 7µs | 7µs | Class::MOP::Object::BEGIN@3 |
| 1 | 1 | 1 | 5µs | 18µs | Class::MOP::Object::BEGIN@10 |
| 1 | 1 | 1 | 5µs | 8µs | Class::MOP::Object::BEGIN@11 |
| 1 | 1 | 1 | 5µs | 24µs | Class::MOP::Object::BEGIN@13 |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Object::_get_compatible_metaclass |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Object::_get_compatible_metaclass_by_subclassing |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Object::_make_compatible_with |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Object::_real_ref_name |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Object::dump |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | package Class::MOP::Object; | ||||
| 3 | # spent 7µs within Class::MOP::Object::BEGIN@3 which was called:
# once (7µs+0s) by base::import at line 5 | ||||
| 4 | 1 | 4µs | $Class::MOP::Object::AUTHORITY = 'cpan:STEVAN'; | ||
| 5 | 1 | 25µs | 1 | 7µs | } # spent 7µs making 1 call to Class::MOP::Object::BEGIN@3 |
| 6 | { | ||||
| 7 | 2 | 800ns | $Class::MOP::Object::VERSION = '2.1005'; | ||
| 8 | } | ||||
| 9 | |||||
| 10 | 2 | 20µs | 2 | 30µs | # spent 18µs (5+12) within Class::MOP::Object::BEGIN@10 which was called:
# once (5µs+12µs) by base::import at line 10 # spent 18µs making 1 call to Class::MOP::Object::BEGIN@10
# spent 12µs making 1 call to strict::import |
| 11 | 2 | 20µs | 2 | 12µs | # spent 8µs (5+3) within Class::MOP::Object::BEGIN@11 which was called:
# once (5µs+3µs) by base::import at line 11 # spent 8µs making 1 call to Class::MOP::Object::BEGIN@11
# spent 3µs making 1 call to warnings::import |
| 12 | |||||
| 13 | 2 | 19µs | 2 | 42µs | # spent 24µs (5+19) within Class::MOP::Object::BEGIN@13 which was called:
# once (5µs+19µs) by base::import at line 13 # spent 24µs making 1 call to Class::MOP::Object::BEGIN@13
# spent 18µs making 1 call to Exporter::import |
| 14 | 2 | 339µs | 2 | 40µs | # spent 24µs (8+16) within Class::MOP::Object::BEGIN@14 which was called:
# once (8µs+16µs) by base::import at line 14 # spent 24µs making 1 call to Class::MOP::Object::BEGIN@14
# spent 16µs making 1 call to Exporter::import |
| 15 | |||||
| 16 | # introspection | ||||
| 17 | |||||
| 18 | sub meta { | ||||
| 19 | 33 | 9µs | require Class::MOP::Class; | ||
| 20 | 33 | 177µs | 66 | 5.21ms | Class::MOP::Class->initialize(blessed($_[0]) || $_[0]); # spent 5.20ms making 33 calls to Class::MOP::Class::initialize, avg 158µs/call
# spent 14µs making 33 calls to Scalar::Util::blessed, avg 409ns/call |
| 21 | } | ||||
| 22 | |||||
| 23 | # spent 193µs (8+184) within Class::MOP::Object::_new which was called:
# once (8µs+184µs) by Moose::Meta::TypeConstraint::Registry::new at line 33 of Moose/Meta/TypeConstraint/Registry.pm | ||||
| 24 | 1 | 5µs | 2 | 184µs | Class::MOP::class_of(shift)->new_object(@_); # spent 180µs making 1 call to Class::MOP::Class::new_object
# spent 5µs making 1 call to Class::MOP::class_of |
| 25 | } | ||||
| 26 | |||||
| 27 | # RANT: | ||||
| 28 | # Cmon, how many times have you written | ||||
| 29 | # the following code while debugging: | ||||
| 30 | # | ||||
| 31 | # use Data::Dumper; | ||||
| 32 | # warn Dumper $obj; | ||||
| 33 | # | ||||
| 34 | # It can get seriously annoying, so why | ||||
| 35 | # not just do this ... | ||||
| 36 | sub dump { | ||||
| 37 | my $self = shift; | ||||
| 38 | require Data::Dumper; | ||||
| 39 | local $Data::Dumper::Maxdepth = shift || 1; | ||||
| 40 | Data::Dumper::Dumper $self; | ||||
| 41 | } | ||||
| 42 | |||||
| 43 | sub _real_ref_name { | ||||
| 44 | my $self = shift; | ||||
| 45 | return blessed($self); | ||||
| 46 | } | ||||
| 47 | |||||
| 48 | # spent 1.77ms (1.32+443µs) within Class::MOP::Object::_is_compatible_with which was called 526 times, avg 3µs/call:
# 398 times (1.01ms+341µs) by Class::MOP::Object::_can_be_made_compatible_with at line 57, avg 3µs/call
# 108 times (263µs+91µs) by Class::MOP::Class::_single_metaclass_is_compatible at line 295 of Class/MOP/Class.pm, avg 3µs/call
# 20 times (53µs+10µs) by Class::MOP::Class::_class_metaclass_is_compatible at line 257 of Class/MOP/Class.pm, avg 3µs/call | ||||
| 49 | 526 | 67µs | my $self = shift; | ||
| 50 | 526 | 75µs | my ($other_name) = @_; | ||
| 51 | |||||
| 52 | 526 | 1.87ms | 526 | 442µs | return $self->isa($other_name); # spent 442µs making 526 calls to UNIVERSAL::isa, avg 841ns/call |
| 53 | } | ||||
| 54 | |||||
| 55 | # spent 2.34ms (988µs+1.35) within Class::MOP::Object::_can_be_made_compatible_with which was called 398 times, avg 6µs/call:
# 333 times (794µs+1.10ms) by Class::MOP::Class::_single_metaclass_can_be_made_compatible at line 365 of Class/MOP/Class.pm, avg 6µs/call
# 65 times (194µs+250µs) by Class::MOP::Class::_class_metaclass_can_be_made_compatible at line 345 of Class/MOP/Class.pm, avg 7µs/call | ||||
| 56 | 398 | 59µs | my $self = shift; | ||
| 57 | 398 | 802µs | 398 | 1.35ms | return !$self->_is_compatible_with(@_) # spent 1.35ms making 398 calls to Class::MOP::Object::_is_compatible_with, avg 3µs/call |
| 58 | && defined($self->_get_compatible_metaclass(@_)); | ||||
| 59 | } | ||||
| 60 | |||||
| 61 | sub _make_compatible_with { | ||||
| 62 | my $self = shift; | ||||
| 63 | my ($other_name) = @_; | ||||
| 64 | |||||
| 65 | my $new_metaclass = $self->_get_compatible_metaclass($other_name); | ||||
| 66 | |||||
| 67 | confess "Can't make $self compatible with metaclass $other_name" | ||||
| 68 | unless defined $new_metaclass; | ||||
| 69 | |||||
| 70 | # can't use rebless_instance here, because it might not be an actual | ||||
| 71 | # subclass in the case of, e.g. moose role reconciliation | ||||
| 72 | $new_metaclass->meta->_force_rebless_instance($self) | ||||
| 73 | if blessed($self) ne $new_metaclass; | ||||
| 74 | |||||
| 75 | return $self; | ||||
| 76 | } | ||||
| 77 | |||||
| 78 | sub _get_compatible_metaclass { | ||||
| 79 | my $self = shift; | ||||
| 80 | my ($other_name) = @_; | ||||
| 81 | |||||
| 82 | return $self->_get_compatible_metaclass_by_subclassing($other_name); | ||||
| 83 | } | ||||
| 84 | |||||
| 85 | sub _get_compatible_metaclass_by_subclassing { | ||||
| 86 | my $self = shift; | ||||
| 87 | my ($other_name) = @_; | ||||
| 88 | my $meta_name = blessed($self) ? $self->_real_ref_name : $self; | ||||
| 89 | |||||
| 90 | if ($meta_name->isa($other_name)) { | ||||
| 91 | return $meta_name; | ||||
| 92 | } | ||||
| 93 | elsif ($other_name->isa($meta_name)) { | ||||
| 94 | return $other_name; | ||||
| 95 | } | ||||
| 96 | |||||
| 97 | return; | ||||
| 98 | } | ||||
| 99 | |||||
| 100 | 1 | 2µs | 1; | ||
| 101 | |||||
| 102 | # ABSTRACT: Base class for metaclasses | ||||
| 103 | |||||
| 104 | __END__ |