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