| Filename | /home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/TypeConstraint/Class.pm |
| Statements | Executed 532 statements in 14.6ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 86 | 2 | 2 | 4.11ms | 5.94ms | Moose::Meta::TypeConstraint::Class::__ANON__[:38] |
| 47 | 1 | 1 | 4.06ms | 26.4ms | Moose::Meta::TypeConstraint::Class::new |
| 47 | 1 | 1 | 2.53ms | 3.92ms | Moose::Meta::TypeConstraint::Class::_create_hand_optimized_type_constraint |
| 1 | 1 | 1 | 71µs | 89µs | Moose::Meta::TypeConstraint::Class::BEGIN@3 |
| 1 | 1 | 1 | 41µs | 201µs | Moose::Meta::TypeConstraint::Class::BEGIN@7 |
| 1 | 1 | 1 | 38µs | 281µs | Moose::Meta::TypeConstraint::Class::BEGIN@14 |
| 1 | 1 | 1 | 38µs | 107µs | Moose::Meta::TypeConstraint::Class::BEGIN@4 |
| 1 | 1 | 1 | 37µs | 3.00ms | Moose::Meta::TypeConstraint::Class::BEGIN@5 |
| 1 | 1 | 1 | 20µs | 20µs | Moose::Meta::TypeConstraint::Class::BEGIN@8 |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Class::create_child_type |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Class::equals |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Class::get_message |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Class::is_a_type_of |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Class::is_subtype_of |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Class::parents |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Moose::Meta::TypeConstraint::Class; | ||||
| 2 | |||||
| 3 | 3 | 100µs | 2 | 108µs | # spent 89µs (71+19) within Moose::Meta::TypeConstraint::Class::BEGIN@3 which was called:
# once (71µs+19µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 3 # spent 89µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@3
# spent 19µs making 1 call to strict::import |
| 4 | 3 | 94µs | 2 | 175µs | # spent 107µs (38+69) within Moose::Meta::TypeConstraint::Class::BEGIN@4 which was called:
# once (38µs+69µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 4 # spent 107µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@4
# spent 69µs making 1 call to warnings::import |
| 5 | 3 | 148µs | 2 | 5.97ms | # spent 3.00ms (37µs+2.97) within Moose::Meta::TypeConstraint::Class::BEGIN@5 which was called:
# once (37µs+2.97ms) by Moose::Util::TypeConstraints::BEGIN@33 at line 5 # spent 3.00ms making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@5
# spent 2.97ms making 1 call to metaclass::import |
| 6 | |||||
| 7 | 3 | 102µs | 2 | 362µs | # spent 201µs (41+160) within Moose::Meta::TypeConstraint::Class::BEGIN@7 which was called:
# once (41µs+160µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 7 # spent 201µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@7
# spent 160µs making 1 call to Exporter::import |
| 8 | 3 | 216µs | 1 | 20µs | # spent 20µs within Moose::Meta::TypeConstraint::Class::BEGIN@8 which was called:
# once (20µs+0s) by Moose::Util::TypeConstraints::BEGIN@33 at line 8 # spent 20µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@8 |
| 9 | |||||
| 10 | 1 | 5µs | our $VERSION = '1.19'; | ||
| 11 | 1 | 66µs | $VERSION = eval $VERSION; # spent 11µs executing statements in string eval | ||
| 12 | 1 | 4µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 13 | |||||
| 14 | 3 | 1.96ms | 2 | 524µs | # spent 281µs (38+243) within Moose::Meta::TypeConstraint::Class::BEGIN@14 which was called:
# once (38µs+243µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 14 # spent 281µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@14
# spent 243µs making 1 call to base::import |
| 15 | |||||
| 16 | 1 | 28µs | 2 | 2.25ms | __PACKAGE__->meta->add_attribute('class' => ( # spent 2.13ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 120µs making 1 call to Moose::Meta::TypeConstraint::Class::meta |
| 17 | reader => 'class', | ||||
| 18 | )); | ||||
| 19 | |||||
| 20 | # spent 26.4ms (4.06+22.4) within Moose::Meta::TypeConstraint::Class::new which was called 47 times, avg 562µs/call:
# 47 times (4.06ms+22.4ms) by Moose::Util::TypeConstraints::create_class_type_constraint at line 152 of Moose/Util/TypeConstraints.pm, avg 562µs/call | ||||
| 21 | 47 | 371µs | my ( $class, %args ) = @_; | ||
| 22 | |||||
| 23 | 47 | 536µs | 47 | 5.98ms | $args{parent} = Moose::Util::TypeConstraints::find_type_constraint('Object'); # spent 5.98ms making 47 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 127µs/call |
| 24 | 47 | 728µs | 47 | 5.60ms | my $self = $class->_new(\%args); # spent 5.60ms making 47 calls to Moose::Meta::TypeConstraint::Class::_new, avg 119µs/call |
| 25 | |||||
| 26 | 47 | 584µs | 47 | 3.92ms | $self->_create_hand_optimized_type_constraint; # spent 3.92ms making 47 calls to Moose::Meta::TypeConstraint::Class::_create_hand_optimized_type_constraint, avg 83µs/call |
| 27 | 47 | 570µs | 47 | 6.87ms | $self->compile_type_constraint(); # spent 6.87ms making 47 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 146µs/call |
| 28 | |||||
| 29 | 47 | 728µs | return $self; | ||
| 30 | } | ||||
| 31 | |||||
| 32 | # spent 3.92ms (2.53+1.39) within Moose::Meta::TypeConstraint::Class::_create_hand_optimized_type_constraint which was called 47 times, avg 83µs/call:
# 47 times (2.53ms+1.39ms) by Moose::Meta::TypeConstraint::Class::new at line 26, avg 83µs/call | ||||
| 33 | 47 | 135µs | my $self = shift; | ||
| 34 | 47 | 538µs | 47 | 602µs | my $class = $self->class; # spent 602µs making 47 calls to Moose::Meta::TypeConstraint::Class::class, avg 13µs/call |
| 35 | $self->hand_optimized_type_constraint( | ||||
| 36 | # spent 5.94ms (4.11+1.83) within Moose::Meta::TypeConstraint::Class::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/TypeConstraint/Class.pm:38] which was called 86 times, avg 69µs/call:
# 84 times (3.98ms+1.79ms) by Moose::Meta::TypeConstraint::check at line 115 of Moose/Meta/TypeConstraint.pm, avg 69µs/call
# 2 times (124µs+49µs) by MooseX::Role::Parameterized::Meta::Role::Parameterizable::parameters_metaclass at line 46 of accessor parameters_metaclass defined at MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm, avg 87µs/call | ||||
| 37 | 86 | 6.12ms | 258 | 1.83ms | blessed( $_[0] ) && blessed( $_[0] ) ne 'Regexp' && $_[0]->isa($class) # spent 1.19ms making 172 calls to Scalar::Util::blessed, avg 7µs/call
# spent 644µs making 86 calls to UNIVERSAL::isa, avg 7µs/call |
| 38 | } | ||||
| 39 | 47 | 1.51ms | 47 | 783µs | ); # spent 783µs making 47 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 17µs/call |
| 40 | } | ||||
| 41 | |||||
| 42 | sub parents { | ||||
| 43 | my $self = shift; | ||||
| 44 | return ( | ||||
| 45 | $self->parent, | ||||
| 46 | map { | ||||
| 47 | # FIXME find_type_constraint might find a TC named after the class but that isn't really it | ||||
| 48 | # I did this anyway since it's a convention that preceded TypeConstraint::Class, and it should DWIM | ||||
| 49 | # if anybody thinks this problematic please discuss on IRC. | ||||
| 50 | # a possible fix is to add by attr indexing to the type registry to find types of a certain property | ||||
| 51 | # regardless of their name | ||||
| 52 | Moose::Util::TypeConstraints::find_type_constraint($_) | ||||
| 53 | || | ||||
| 54 | __PACKAGE__->new( class => $_, name => "__ANON__" ) | ||||
| 55 | } Class::MOP::class_of($self->class)->superclasses, | ||||
| 56 | ); | ||||
| 57 | } | ||||
| 58 | |||||
| 59 | sub equals { | ||||
| 60 | my ( $self, $type_or_name ) = @_; | ||||
| 61 | |||||
| 62 | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); | ||||
| 63 | |||||
| 64 | return unless defined $other; | ||||
| 65 | return unless $other->isa(__PACKAGE__); | ||||
| 66 | |||||
| 67 | return $self->class eq $other->class; | ||||
| 68 | } | ||||
| 69 | |||||
| 70 | sub is_a_type_of { | ||||
| 71 | my ($self, $type_or_name) = @_; | ||||
| 72 | |||||
| 73 | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); | ||||
| 74 | |||||
| 75 | ($self->equals($type) || $self->is_subtype_of($type_or_name)); | ||||
| 76 | } | ||||
| 77 | |||||
| 78 | sub is_subtype_of { | ||||
| 79 | my ($self, $type_or_name_or_class ) = @_; | ||||
| 80 | |||||
| 81 | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name_or_class); | ||||
| 82 | |||||
| 83 | if ( not defined $type ) { | ||||
| 84 | if ( not ref $type_or_name_or_class ) { | ||||
| 85 | # it might be a class | ||||
| 86 | return 1 if $self->class->isa( $type_or_name_or_class ); | ||||
| 87 | } | ||||
| 88 | return; | ||||
| 89 | } | ||||
| 90 | |||||
| 91 | if ( $type->isa(__PACKAGE__) && $type->class ne $self->class) { | ||||
| 92 | # if $type_or_name_or_class isn't a class, it might be the TC name of another ::Class type | ||||
| 93 | # or it could also just be a type object in this branch | ||||
| 94 | return $self->class->isa( $type->class ); | ||||
| 95 | } else { | ||||
| 96 | # the only other thing we are a subtype of is Object | ||||
| 97 | $self->SUPER::is_subtype_of($type); | ||||
| 98 | } | ||||
| 99 | } | ||||
| 100 | |||||
| 101 | # This is a bit counter-intuitive, but a child type of a Class type | ||||
| 102 | # constraint is not itself a Class type constraint (it has no class | ||||
| 103 | # attribute). This whole create_child_type thing needs some changing | ||||
| 104 | # though, probably making MMC->new a factory or something. | ||||
| 105 | sub create_child_type { | ||||
| 106 | my ($self, @args) = @_; | ||||
| 107 | return Moose::Meta::TypeConstraint->new(@args, parent => $self); | ||||
| 108 | } | ||||
| 109 | |||||
| 110 | sub get_message { | ||||
| 111 | my $self = shift; | ||||
| 112 | my ($value) = @_; | ||||
| 113 | |||||
| 114 | if ($self->has_message) { | ||||
| 115 | return $self->SUPER::get_message(@_); | ||||
| 116 | } | ||||
| 117 | |||||
| 118 | $value = (defined $value ? overload::StrVal($value) : 'undef'); | ||||
| 119 | return "Validation failed for '" . $self->name . "' with value $value (not isa " . $self->class . ")"; | ||||
| 120 | } | ||||
| 121 | |||||
| 122 | 1 | 25µs | 1; | ||
| 123 | |||||
| 124 | __END__ |