| Filename | /Users/ap13/perl5/lib/perl5/darwin-2level/Moose/Meta/TypeConstraint/Class.pm |
| Statements | Executed 443 statements in 2.05ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 83 | 1 | 1 | 733µs | 1.14ms | Moose::Meta::TypeConstraint::Class::__ANON__[:25] |
| 22 | 1 | 1 | 600µs | 13.9ms | Moose::Meta::TypeConstraint::Class::new |
| 1 | 1 | 1 | 21µs | 43µs | Moose::Meta::TypeConstraint::Class::BEGIN@8 |
| 1 | 1 | 1 | 15µs | 32µs | Moose::Meta::TypeConstraint::Class::BEGIN@4 |
| 1 | 1 | 1 | 9µs | 15µs | Moose::Meta::TypeConstraint::Class::BEGIN@5 |
| 1 | 1 | 1 | 7µs | 33µs | Moose::Meta::TypeConstraint::Class::BEGIN@12 |
| 1 | 1 | 1 | 7µs | 508µs | Moose::Meta::TypeConstraint::Class::BEGIN@6 |
| 1 | 1 | 1 | 3µs | 3µs | Moose::Meta::TypeConstraint::Class::BEGIN@10 |
| 1 | 1 | 1 | 3µs | 3µs | Moose::Meta::TypeConstraint::Class::BEGIN@9 |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Class::__ANON__[:34] |
| 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 | 1 | 800ns | our $VERSION = '2.1403'; | ||
| 3 | |||||
| 4 | 2 | 24µs | 2 | 48µs | # spent 32µs (15+17) within Moose::Meta::TypeConstraint::Class::BEGIN@4 which was called:
# once (15µs+17µs) by Moose::Util::TypeConstraints::BEGIN@28 at line 4 # spent 32µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@4
# spent 17µs making 1 call to strict::import |
| 5 | 2 | 20µs | 2 | 21µs | # spent 15µs (9+6) within Moose::Meta::TypeConstraint::Class::BEGIN@5 which was called:
# once (9µs+6µs) by Moose::Util::TypeConstraints::BEGIN@28 at line 5 # spent 15µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@5
# spent 6µs making 1 call to warnings::import |
| 6 | 2 | 40µs | 2 | 1.01ms | # spent 508µs (7+501) within Moose::Meta::TypeConstraint::Class::BEGIN@6 which was called:
# once (7µs+501µs) by Moose::Util::TypeConstraints::BEGIN@28 at line 6 # spent 508µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@6
# spent 501µs making 1 call to metaclass::import |
| 7 | |||||
| 8 | 2 | 26µs | 2 | 65µs | # spent 43µs (21+22) within Moose::Meta::TypeConstraint::Class::BEGIN@8 which was called:
# once (21µs+22µs) by Moose::Util::TypeConstraints::BEGIN@28 at line 8 # spent 43µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@8
# spent 22µs making 1 call to Exporter::import |
| 9 | 2 | 24µs | 1 | 3µs | # spent 3µs within Moose::Meta::TypeConstraint::Class::BEGIN@9 which was called:
# once (3µs+0s) by Moose::Util::TypeConstraints::BEGIN@28 at line 9 # spent 3µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@9 |
| 10 | 2 | 23µs | 1 | 3µs | # spent 3µs within Moose::Meta::TypeConstraint::Class::BEGIN@10 which was called:
# once (3µs+0s) by Moose::Util::TypeConstraints::BEGIN@28 at line 10 # spent 3µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@10 |
| 11 | |||||
| 12 | 2 | 548µs | 2 | 58µs | # spent 33µs (7+25) within Moose::Meta::TypeConstraint::Class::BEGIN@12 which was called:
# once (7µs+25µs) by Moose::Util::TypeConstraints::BEGIN@28 at line 12 # spent 33µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@12
# spent 25µs making 1 call to parent::import |
| 13 | |||||
| 14 | 1 | 6µs | 3 | 351µs | __PACKAGE__->meta->add_attribute('class' => ( # spent 328µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 17µs making 1 call to Moose::Meta::TypeConstraint::Class::meta
# spent 6µs making 1 call to Class::MOP::_definition_context |
| 15 | reader => 'class', | ||||
| 16 | Class::MOP::_definition_context(), | ||||
| 17 | )); | ||||
| 18 | |||||
| 19 | # spent 1.14ms (733µs+407µs) within Moose::Meta::TypeConstraint::Class::__ANON__[/Users/ap13/perl5/lib/perl5/darwin-2level/Moose/Meta/TypeConstraint/Class.pm:25] which was called 83 times, avg 14µs/call:
# 83 times (733µs+407µs) by Moose::Meta::TypeConstraint::_inline_check at line 195 of Moose/Meta/TypeConstraint.pm, avg 14µs/call | ||||
| 20 | 83 | 24µs | my $self = shift; | ||
| 21 | 83 | 24µs | my $val = shift; | ||
| 22 | |||||
| 23 | 83 | 781µs | 166 | 407µs | return 'Scalar::Util::blessed(' . $val . ')' # spent 224µs making 83 calls to B::perlstring, avg 3µs/call
# spent 184µs making 83 calls to Moose::Meta::TypeConstraint::Class::class, avg 2µs/call |
| 24 | . ' && ' . $val . '->isa(' . B::perlstring($self->class) . ')'; | ||||
| 25 | 1 | 2µs | }; | ||
| 26 | |||||
| 27 | # spent 13.9ms (600µs+13.3) within Moose::Meta::TypeConstraint::Class::new which was called 22 times, avg 634µs/call:
# 22 times (600µs+13.3ms) by Moose::Util::TypeConstraints::create_class_type_constraint at line 176 of Moose/Util/TypeConstraints.pm, avg 634µs/call | ||||
| 28 | 22 | 45µs | my ( $class, %args ) = @_; | ||
| 29 | |||||
| 30 | 22 | 37µs | 22 | 412µs | $args{parent} # spent 412µs making 22 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 19µs/call |
| 31 | = Moose::Util::TypeConstraints::find_type_constraint('Object'); | ||||
| 32 | |||||
| 33 | 22 | 14µs | my $class_name = $args{class}; | ||
| 34 | 22 | 76µs | $args{constraint} = sub { $_[0]->isa($class_name) }; | ||
| 35 | |||||
| 36 | 22 | 16µs | $args{inlined} = $inliner; | ||
| 37 | |||||
| 38 | 22 | 177µs | 22 | 8.25ms | my $self = $class->SUPER::new( \%args ); # spent 8.25ms making 22 calls to Moose::Meta::TypeConstraint::new, avg 375µs/call |
| 39 | |||||
| 40 | 22 | 49µs | 22 | 4.68ms | $self->compile_type_constraint(); # spent 4.68ms making 22 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 213µs/call |
| 41 | |||||
| 42 | 22 | 89µs | return $self; | ||
| 43 | } | ||||
| 44 | |||||
| 45 | sub parents { | ||||
| 46 | my $self = shift; | ||||
| 47 | return ( | ||||
| 48 | $self->parent, | ||||
| 49 | map { | ||||
| 50 | # FIXME find_type_constraint might find a TC named after the class but that isn't really it | ||||
| 51 | # I did this anyway since it's a convention that preceded TypeConstraint::Class, and it should DWIM | ||||
| 52 | # if anybody thinks this problematic please discuss on IRC. | ||||
| 53 | # a possible fix is to add by attr indexing to the type registry to find types of a certain property | ||||
| 54 | # regardless of their name | ||||
| 55 | Moose::Util::TypeConstraints::find_type_constraint($_) | ||||
| 56 | || | ||||
| 57 | __PACKAGE__->new( class => $_, name => "__ANON__" ) | ||||
| 58 | } Class::MOP::class_of($self->class)->superclasses, | ||||
| 59 | ); | ||||
| 60 | } | ||||
| 61 | |||||
| 62 | sub equals { | ||||
| 63 | my ( $self, $type_or_name ) = @_; | ||||
| 64 | |||||
| 65 | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); | ||||
| 66 | |||||
| 67 | if (!defined($other)) { | ||||
| 68 | if (!ref($type_or_name)) { | ||||
| 69 | return $self->class eq $type_or_name; | ||||
| 70 | } | ||||
| 71 | return; | ||||
| 72 | } | ||||
| 73 | |||||
| 74 | return unless $other->isa(__PACKAGE__); | ||||
| 75 | |||||
| 76 | return $self->class eq $other->class; | ||||
| 77 | } | ||||
| 78 | |||||
| 79 | sub is_a_type_of { | ||||
| 80 | my ($self, $type_or_name) = @_; | ||||
| 81 | |||||
| 82 | ($self->equals($type_or_name) || $self->is_subtype_of($type_or_name)); | ||||
| 83 | } | ||||
| 84 | |||||
| 85 | sub is_subtype_of { | ||||
| 86 | my ($self, $type_or_name_or_class ) = @_; | ||||
| 87 | |||||
| 88 | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name_or_class); | ||||
| 89 | |||||
| 90 | if ( not defined $type ) { | ||||
| 91 | if ( not ref $type_or_name_or_class ) { | ||||
| 92 | # it might be a class | ||||
| 93 | my $class = $self->class; | ||||
| 94 | return 1 if $class ne $type_or_name_or_class | ||||
| 95 | && $class->isa( $type_or_name_or_class ); | ||||
| 96 | } | ||||
| 97 | return; | ||||
| 98 | } | ||||
| 99 | |||||
| 100 | if ( $type->isa(__PACKAGE__) && $type->class ne $self->class) { | ||||
| 101 | # if $type_or_name_or_class isn't a class, it might be the TC name of another ::Class type | ||||
| 102 | # or it could also just be a type object in this branch | ||||
| 103 | return $self->class->isa( $type->class ); | ||||
| 104 | } else { | ||||
| 105 | # the only other thing we are a subtype of is Object | ||||
| 106 | $self->SUPER::is_subtype_of($type); | ||||
| 107 | } | ||||
| 108 | } | ||||
| 109 | |||||
| 110 | # This is a bit counter-intuitive, but a child type of a Class type | ||||
| 111 | # constraint is not itself a Class type constraint (it has no class | ||||
| 112 | # attribute). This whole create_child_type thing needs some changing | ||||
| 113 | # though, probably making MMC->new a factory or something. | ||||
| 114 | sub create_child_type { | ||||
| 115 | my ($self, @args) = @_; | ||||
| 116 | return Moose::Meta::TypeConstraint->new(@args, parent => $self); | ||||
| 117 | } | ||||
| 118 | |||||
| 119 | sub get_message { | ||||
| 120 | my $self = shift; | ||||
| 121 | my ($value) = @_; | ||||
| 122 | |||||
| 123 | if ($self->has_message) { | ||||
| 124 | return $self->SUPER::get_message(@_); | ||||
| 125 | } | ||||
| 126 | |||||
| 127 | $value = (defined $value ? overload::StrVal($value) : 'undef'); | ||||
| 128 | return "Validation failed for '" . $self->name . "' with value $value (not isa " . $self->class . ")"; | ||||
| 129 | } | ||||
| 130 | |||||
| 131 | 1 | 7µs | 1; | ||
| 132 | |||||
| 133 | # ABSTRACT: Class/TypeConstraint parallel hierarchy | ||||
| 134 | |||||
| 135 | __END__ |