Filename | /usr/local/lib/perl/5.14.2/Moose/Meta/TypeConstraint/Parameterized.pm |
Statements | Executed 20 statements in 684µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 660µs | 2.22ms | BEGIN@15 | Moose::Meta::TypeConstraint::Parameterized::
1 | 1 | 1 | 9µs | 9µs | BEGIN@2 | Moose::Meta::TypeConstraint::Parameterized::
1 | 1 | 1 | 8µs | 8µs | BEGIN@14 | Moose::Meta::TypeConstraint::Parameterized::
1 | 1 | 1 | 8µs | 11µs | BEGIN@9 | Moose::Meta::TypeConstraint::Parameterized::
1 | 1 | 1 | 7µs | 15µs | BEGIN@10 | Moose::Meta::TypeConstraint::Parameterized::
1 | 1 | 1 | 7µs | 34µs | BEGIN@13 | Moose::Meta::TypeConstraint::Parameterized::
1 | 1 | 1 | 7µs | 47µs | BEGIN@17 | Moose::Meta::TypeConstraint::Parameterized::
1 | 1 | 1 | 6µs | 408µs | BEGIN@11 | Moose::Meta::TypeConstraint::Parameterized::
0 | 0 | 0 | 0s | 0s | _inline_check | Moose::Meta::TypeConstraint::Parameterized::
0 | 0 | 0 | 0s | 0s | can_be_inlined | Moose::Meta::TypeConstraint::Parameterized::
0 | 0 | 0 | 0s | 0s | compile_type_constraint | Moose::Meta::TypeConstraint::Parameterized::
0 | 0 | 0 | 0s | 0s | create_child_type | Moose::Meta::TypeConstraint::Parameterized::
0 | 0 | 0 | 0s | 0s | equals | Moose::Meta::TypeConstraint::Parameterized::
0 | 0 | 0 | 0s | 0s | inline_environment | Moose::Meta::TypeConstraint::Parameterized::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Moose::Meta::TypeConstraint::Parameterized; | ||||
2 | # spent 9µs within Moose::Meta::TypeConstraint::Parameterized::BEGIN@2 which was called:
# once (9µs+0s) by Moose::Util::TypeConstraints::BEGIN@34 at line 4 | ||||
3 | 1 | 5µs | $Moose::Meta::TypeConstraint::Parameterized::AUTHORITY = 'cpan:STEVAN'; | ||
4 | 1 | 31µs | 1 | 9µs | } # spent 9µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::BEGIN@2 |
5 | { | ||||
6 | 2 | 1µs | $Moose::Meta::TypeConstraint::Parameterized::VERSION = '2.1005'; | ||
7 | } | ||||
8 | |||||
9 | 2 | 22µs | 2 | 14µs | # spent 11µs (8+3) within Moose::Meta::TypeConstraint::Parameterized::BEGIN@9 which was called:
# once (8µs+3µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 9 # spent 11µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::BEGIN@9
# spent 3µs making 1 call to strict::import |
10 | 2 | 22µs | 2 | 24µs | # spent 15µs (7+8) within Moose::Meta::TypeConstraint::Parameterized::BEGIN@10 which was called:
# once (7µs+8µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 10 # spent 15µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::BEGIN@10
# spent 8µs making 1 call to warnings::import |
11 | 2 | 30µs | 2 | 810µs | # spent 408µs (6+402) within Moose::Meta::TypeConstraint::Parameterized::BEGIN@11 which was called:
# once (6µs+402µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 11 # spent 408µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::BEGIN@11
# spent 402µs making 1 call to metaclass::import |
12 | |||||
13 | 2 | 24µs | 2 | 61µs | # spent 34µs (7+27) within Moose::Meta::TypeConstraint::Parameterized::BEGIN@13 which was called:
# once (7µs+27µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 13 # spent 34µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::BEGIN@13
# spent 27µs making 1 call to Exporter::import |
14 | 2 | 25µs | 1 | 8µs | # spent 8µs within Moose::Meta::TypeConstraint::Parameterized::BEGIN@14 which was called:
# once (8µs+0s) by Moose::Util::TypeConstraints::BEGIN@34 at line 14 # spent 8µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::BEGIN@14 |
15 | 2 | 114µs | 1 | 2.22ms | # spent 2.22ms (660µs+1.56) within Moose::Meta::TypeConstraint::Parameterized::BEGIN@15 which was called:
# once (660µs+1.56ms) by Moose::Util::TypeConstraints::BEGIN@34 at line 15 # spent 2.22ms making 1 call to Moose::Meta::TypeConstraint::Parameterized::BEGIN@15 |
16 | |||||
17 | 2 | 395µs | 2 | 87µs | # spent 47µs (7+40) within Moose::Meta::TypeConstraint::Parameterized::BEGIN@17 which was called:
# once (7µs+40µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 17 # spent 47µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::BEGIN@17
# spent 40µs making 1 call to base::import |
18 | |||||
19 | 1 | 4µs | 3 | 517µs | __PACKAGE__->meta->add_attribute('type_parameter' => ( # spent 495µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 16µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::meta
# spent 6µs making 1 call to Class::MOP::_definition_context |
20 | accessor => 'type_parameter', | ||||
21 | predicate => 'has_type_parameter', | ||||
22 | Class::MOP::_definition_context(), | ||||
23 | )); | ||||
24 | |||||
25 | 1 | 4µs | 3 | 490µs | __PACKAGE__->meta->add_attribute('parameterized_from' => ( # spent 473µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 11µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
26 | accessor => 'parameterized_from', | ||||
27 | predicate => 'has_parameterized_from', | ||||
28 | Class::MOP::_definition_context(), | ||||
29 | )); | ||||
30 | |||||
31 | sub equals { | ||||
32 | my ( $self, $type_or_name ) = @_; | ||||
33 | |||||
34 | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); | ||||
35 | |||||
36 | return unless $other->isa(__PACKAGE__); | ||||
37 | |||||
38 | return ( | ||||
39 | $self->type_parameter->equals( $other->type_parameter ) | ||||
40 | and | ||||
41 | $self->parent->equals( $other->parent ) | ||||
42 | ); | ||||
43 | } | ||||
44 | |||||
45 | sub compile_type_constraint { | ||||
46 | my $self = shift; | ||||
47 | |||||
48 | unless ( $self->has_type_parameter ) { | ||||
49 | require Moose; | ||||
50 | Moose->throw_error("You cannot create a Higher Order type without a type parameter"); | ||||
51 | } | ||||
52 | |||||
53 | my $type_parameter = $self->type_parameter; | ||||
54 | |||||
55 | unless ( blessed $type_parameter && $type_parameter->isa('Moose::Meta::TypeConstraint') ) { | ||||
56 | require Moose; | ||||
57 | Moose->throw_error("The type parameter must be a Moose meta type"); | ||||
58 | } | ||||
59 | |||||
60 | foreach my $type (Moose::Util::TypeConstraints::get_all_parameterizable_types()) { | ||||
61 | if (my $constraint = $type->generate_constraint_for($self)) { | ||||
62 | $self->_set_constraint($constraint); | ||||
63 | return $self->SUPER::compile_type_constraint; | ||||
64 | } | ||||
65 | } | ||||
66 | |||||
67 | # if we get here, then we couldn't | ||||
68 | # find a way to parameterize this type | ||||
69 | require Moose; | ||||
70 | Moose->throw_error("The " . $self->name . " constraint cannot be used, because " | ||||
71 | . $self->parent->name . " doesn't subtype or coerce from a parameterizable type."); | ||||
72 | } | ||||
73 | |||||
74 | sub can_be_inlined { | ||||
75 | my $self = shift; | ||||
76 | |||||
77 | return | ||||
78 | $self->has_parameterized_from | ||||
79 | && $self->parameterized_from->has_inline_generator | ||||
80 | && $self->type_parameter->can_be_inlined; | ||||
81 | } | ||||
82 | |||||
83 | sub inline_environment { | ||||
84 | my $self = shift; | ||||
85 | |||||
86 | return { | ||||
87 | ($self->has_parameterized_from | ||||
88 | ? (%{ $self->parameterized_from->inline_environment }) | ||||
89 | : ()), | ||||
90 | ($self->has_type_parameter | ||||
91 | ? (%{ $self->type_parameter->inline_environment }) | ||||
92 | : ()), | ||||
93 | }; | ||||
94 | } | ||||
95 | |||||
96 | sub _inline_check { | ||||
97 | my $self = shift; | ||||
98 | |||||
99 | return unless $self->can_be_inlined; | ||||
100 | |||||
101 | return $self->parameterized_from->generate_inline_for( $self->type_parameter, @_ ); | ||||
102 | } | ||||
103 | |||||
104 | sub create_child_type { | ||||
105 | my ($self, %opts) = @_; | ||||
106 | return Moose::Meta::TypeConstraint::Parameterizable->new(%opts, parent=>$self); | ||||
107 | } | ||||
108 | |||||
109 | 1 | 7µs | 1; | ||
110 | |||||
111 | # ABSTRACT: Type constraints with a bound parameter (ArrayRef[Int]) | ||||
112 | |||||
113 | __END__ |