Filename | /opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Meta/TypeConstraint/Parameterized.pm |
Statements | Executed 20 statements in 956µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 936µs | 2.88ms | BEGIN@15 | Moose::Meta::TypeConstraint::Parameterized::
1 | 1 | 1 | 11µs | 11µs | BEGIN@2 | Moose::Meta::TypeConstraint::Parameterized::
1 | 1 | 1 | 10µs | 10µs | BEGIN@14 | Moose::Meta::TypeConstraint::Parameterized::
1 | 1 | 1 | 10µs | 40µs | BEGIN@13 | Moose::Meta::TypeConstraint::Parameterized::
1 | 1 | 1 | 9µs | 78µs | BEGIN@17 | Moose::Meta::TypeConstraint::Parameterized::
1 | 1 | 1 | 9µs | 14µs | BEGIN@10 | Moose::Meta::TypeConstraint::Parameterized::
1 | 1 | 1 | 8µs | 503µs | BEGIN@11 | Moose::Meta::TypeConstraint::Parameterized::
1 | 1 | 1 | 8µs | 23µs | BEGIN@9 | 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 11µs within Moose::Meta::TypeConstraint::Parameterized::BEGIN@2 which was called:
# once (11µs+0s) by Moose::Util::TypeConstraints::BEGIN@34 at line 4 | ||||
3 | 1 | 7µs | $Moose::Meta::TypeConstraint::Parameterized::AUTHORITY = 'cpan:STEVAN'; | ||
4 | 1 | 41µs | 1 | 11µs | } # spent 11µ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 | 30µs | 2 | 38µs | # spent 23µs (8+15) within Moose::Meta::TypeConstraint::Parameterized::BEGIN@9 which was called:
# once (8µs+15µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 9 # spent 23µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::BEGIN@9
# spent 15µs making 1 call to strict::import |
10 | 2 | 34µs | 2 | 18µs | # spent 14µs (9+5) within Moose::Meta::TypeConstraint::Parameterized::BEGIN@10 which was called:
# once (9µs+5µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 10 # spent 14µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::BEGIN@10
# spent 5µs making 1 call to warnings::import |
11 | 2 | 40µs | 2 | 998µs | # spent 503µs (8+495) within Moose::Meta::TypeConstraint::Parameterized::BEGIN@11 which was called:
# once (8µs+495µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 11 # spent 503µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::BEGIN@11
# spent 495µs making 1 call to metaclass::import |
12 | |||||
13 | 2 | 36µs | 2 | 72µs | # spent 40µs (10+31) within Moose::Meta::TypeConstraint::Parameterized::BEGIN@13 which was called:
# once (10µs+31µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 13 # spent 40µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::BEGIN@13
# spent 31µs making 1 call to Exporter::import |
14 | 2 | 40µs | 1 | 10µs | # spent 10µs within Moose::Meta::TypeConstraint::Parameterized::BEGIN@14 which was called:
# once (10µs+0s) by Moose::Util::TypeConstraints::BEGIN@34 at line 14 # spent 10µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::BEGIN@14 |
15 | 2 | 143µs | 1 | 2.88ms | # spent 2.88ms (936µs+1.95) within Moose::Meta::TypeConstraint::Parameterized::BEGIN@15 which was called:
# once (936µs+1.95ms) by Moose::Util::TypeConstraints::BEGIN@34 at line 15 # spent 2.88ms making 1 call to Moose::Meta::TypeConstraint::Parameterized::BEGIN@15 |
16 | |||||
17 | 2 | 566µs | 2 | 147µs | # spent 78µs (9+69) within Moose::Meta::TypeConstraint::Parameterized::BEGIN@17 which was called:
# once (9µs+69µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 17 # spent 78µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::BEGIN@17
# spent 69µs making 1 call to base::import |
18 | |||||
19 | 1 | 5µs | 3 | 645µs | __PACKAGE__->meta->add_attribute('type_parameter' => ( # spent 616µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 22µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::meta
# spent 7µ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 | 609µs | __PACKAGE__->meta->add_attribute('parameterized_from' => ( # spent 589µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 13µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::meta
# spent 7µ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 | 9µs | 1; | ||
110 | |||||
111 | # ABSTRACT: Type constraints with a bound parameter (ArrayRef[Int]) | ||||
112 | |||||
113 | __END__ |