Filename | /opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Meta/TypeConstraint/Parameterizable.pm |
Statements | Executed 20 statements in 860µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 15µs | 19µs | BEGIN@10 | Moose::Meta::TypeConstraint::Parameterizable::
1 | 1 | 1 | 11µs | 11µs | BEGIN@2 | Moose::Meta::TypeConstraint::Parameterizable::
1 | 1 | 1 | 9µs | 90µs | BEGIN@13 | Moose::Meta::TypeConstraint::Parameterizable::
1 | 1 | 1 | 9µs | 9µs | BEGIN@14 | Moose::Meta::TypeConstraint::Parameterizable::
1 | 1 | 1 | 9µs | 38µs | BEGIN@17 | Moose::Meta::TypeConstraint::Parameterizable::
1 | 1 | 1 | 8µs | 493µs | BEGIN@11 | Moose::Meta::TypeConstraint::Parameterizable::
1 | 1 | 1 | 8µs | 23µs | BEGIN@9 | Moose::Meta::TypeConstraint::Parameterizable::
1 | 1 | 1 | 4µs | 4µs | BEGIN@15 | Moose::Meta::TypeConstraint::Parameterizable::
0 | 0 | 0 | 0s | 0s | __ANON__[:53] | Moose::Meta::TypeConstraint::Parameterizable::
0 | 0 | 0 | 0s | 0s | _can_coerce_constraint_from | Moose::Meta::TypeConstraint::Parameterizable::
0 | 0 | 0 | 0s | 0s | _parse_type_parameter | Moose::Meta::TypeConstraint::Parameterizable::
0 | 0 | 0 | 0s | 0s | generate_constraint_for | Moose::Meta::TypeConstraint::Parameterizable::
0 | 0 | 0 | 0s | 0s | generate_inline_for | Moose::Meta::TypeConstraint::Parameterizable::
0 | 0 | 0 | 0s | 0s | parameterize | Moose::Meta::TypeConstraint::Parameterizable::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Moose::Meta::TypeConstraint::Parameterizable; | ||||
2 | # spent 11µs within Moose::Meta::TypeConstraint::Parameterizable::BEGIN@2 which was called:
# once (11µs+0s) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@15 at line 4 | ||||
3 | 1 | 7µs | $Moose::Meta::TypeConstraint::Parameterizable::AUTHORITY = 'cpan:STEVAN'; | ||
4 | 1 | 49µs | 1 | 11µs | } # spent 11µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@2 |
5 | { | ||||
6 | 2 | 1µs | $Moose::Meta::TypeConstraint::Parameterizable::VERSION = '2.1005'; | ||
7 | } | ||||
8 | |||||
9 | 2 | 30µs | 2 | 38µs | # spent 23µs (8+15) within Moose::Meta::TypeConstraint::Parameterizable::BEGIN@9 which was called:
# once (8µs+15µs) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@15 at line 9 # spent 23µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@9
# spent 15µs making 1 call to strict::import |
10 | 2 | 30µs | 2 | 24µs | # spent 19µs (15+4) within Moose::Meta::TypeConstraint::Parameterizable::BEGIN@10 which was called:
# once (15µs+4µs) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@15 at line 10 # spent 19µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@10
# spent 4µs making 1 call to warnings::import |
11 | 2 | 40µs | 2 | 978µs | # spent 493µs (8+485) within Moose::Meta::TypeConstraint::Parameterizable::BEGIN@11 which was called:
# once (8µs+485µs) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@15 at line 11 # spent 493µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@11
# spent 485µs making 1 call to metaclass::import |
12 | |||||
13 | 2 | 41µs | 2 | 170µs | # spent 90µs (9+80) within Moose::Meta::TypeConstraint::Parameterizable::BEGIN@13 which was called:
# once (9µs+80µs) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@15 at line 13 # spent 90µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@13
# spent 80µs making 1 call to base::import |
14 | 2 | 33µs | 1 | 9µs | # spent 9µs within Moose::Meta::TypeConstraint::Parameterizable::BEGIN@14 which was called:
# once (9µs+0s) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@15 at line 14 # spent 9µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@14 |
15 | 2 | 31µs | 1 | 4µs | # spent 4µs within Moose::Meta::TypeConstraint::Parameterizable::BEGIN@15 which was called:
# once (4µs+0s) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@15 at line 15 # spent 4µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@15 |
16 | |||||
17 | 2 | 580µs | 2 | 67µs | # spent 38µs (9+29) within Moose::Meta::TypeConstraint::Parameterizable::BEGIN@17 which was called:
# once (9µs+29µs) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@15 at line 17 # spent 38µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@17
# spent 29µs making 1 call to Exporter::import |
18 | |||||
19 | 1 | 5µs | 3 | 643µs | __PACKAGE__->meta->add_attribute('constraint_generator' => ( # spent 613µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 22µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::meta
# spent 7µs making 1 call to Class::MOP::_definition_context |
20 | accessor => 'constraint_generator', | ||||
21 | predicate => 'has_constraint_generator', | ||||
22 | Class::MOP::_definition_context(), | ||||
23 | )); | ||||
24 | |||||
25 | 1 | 4µs | 3 | 619µs | __PACKAGE__->meta->add_attribute('inline_generator' => ( # spent 600µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 12µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::meta
# spent 7µs making 1 call to Class::MOP::_definition_context |
26 | accessor => 'inline_generator', | ||||
27 | predicate => 'has_inline_generator', | ||||
28 | Class::MOP::_definition_context(), | ||||
29 | )); | ||||
30 | |||||
31 | sub generate_constraint_for { | ||||
32 | my ($self, $type) = @_; | ||||
33 | |||||
34 | return unless $self->has_constraint_generator; | ||||
35 | |||||
36 | return $self->constraint_generator->($type->type_parameter) | ||||
37 | if $type->is_subtype_of($self->name); | ||||
38 | |||||
39 | return $self->_can_coerce_constraint_from($type) | ||||
40 | if $self->has_coercion | ||||
41 | && $self->coercion->has_coercion_for_type($type->parent->name); | ||||
42 | |||||
43 | return; | ||||
44 | } | ||||
45 | |||||
46 | sub _can_coerce_constraint_from { | ||||
47 | my ($self, $type) = @_; | ||||
48 | my $coercion = $self->coercion; | ||||
49 | my $constraint = $self->constraint_generator->($type->type_parameter); | ||||
50 | return sub { | ||||
51 | local $_ = $coercion->coerce($_); | ||||
52 | $constraint->(@_); | ||||
53 | }; | ||||
54 | } | ||||
55 | |||||
56 | sub generate_inline_for { | ||||
57 | my ($self, $type, $val) = @_; | ||||
58 | |||||
59 | confess "Can't generate an inline constraint for $type, since none " | ||||
60 | . "was defined" | ||||
61 | unless $self->has_inline_generator; | ||||
62 | |||||
63 | return '( do { ' . $self->inline_generator->( $self, $type, $val ) . ' } )'; | ||||
64 | } | ||||
65 | |||||
66 | sub _parse_type_parameter { | ||||
67 | my ($self, $type_parameter) = @_; | ||||
68 | return Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($type_parameter); | ||||
69 | } | ||||
70 | |||||
71 | sub parameterize { | ||||
72 | my ($self, $type_parameter) = @_; | ||||
73 | |||||
74 | my $contained_tc = $self->_parse_type_parameter($type_parameter); | ||||
75 | |||||
76 | ## The type parameter should be a subtype of the parent's type parameter | ||||
77 | ## if there is one. | ||||
78 | |||||
79 | if(my $parent = $self->parent) { | ||||
80 | if($parent->can('type_parameter')) { | ||||
81 | unless ( $contained_tc->is_a_type_of($parent->type_parameter) ) { | ||||
82 | require Moose; | ||||
83 | Moose->throw_error("$type_parameter is not a subtype of ".$parent->type_parameter); | ||||
84 | } | ||||
85 | } | ||||
86 | } | ||||
87 | |||||
88 | if ( $contained_tc->isa('Moose::Meta::TypeConstraint') ) { | ||||
89 | my $tc_name = $self->name . '[' . $contained_tc->name . ']'; | ||||
90 | return Moose::Meta::TypeConstraint::Parameterized->new( | ||||
91 | name => $tc_name, | ||||
92 | parent => $self, | ||||
93 | type_parameter => $contained_tc, | ||||
94 | parameterized_from => $self, | ||||
95 | ); | ||||
96 | } | ||||
97 | else { | ||||
98 | require Moose; | ||||
99 | Moose->throw_error("The type parameter must be a Moose meta type"); | ||||
100 | } | ||||
101 | } | ||||
102 | |||||
103 | |||||
104 | 1 | 8µs | 1; | ||
105 | |||||
106 | # ABSTRACT: Type constraints which can take a parameter (ArrayRef) | ||||
107 | |||||
108 | __END__ |