File | /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/TypeConstraint/Parameterized.pm |
Statements Executed | 26 |
Statement Execution Time | 491µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 511µs | 1.16ms | BEGIN@9 | Moose::Meta::TypeConstraint::Parameterized::
1 | 1 | 1 | 18µs | 21µs | BEGIN@3 | Moose::Meta::TypeConstraint::Parameterized::
1 | 1 | 1 | 13µs | 13µs | BEGIN@8 | Moose::Meta::TypeConstraint::Parameterized::
1 | 1 | 1 | 7µs | 16µs | BEGIN@4 | Moose::Meta::TypeConstraint::Parameterized::
1 | 1 | 1 | 7µs | 44µs | BEGIN@15 | Moose::Meta::TypeConstraint::Parameterized::
1 | 1 | 1 | 6µs | 30µs | BEGIN@7 | Moose::Meta::TypeConstraint::Parameterized::
1 | 1 | 1 | 6µs | 99µs | BEGIN@5 | 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::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Moose::Meta::TypeConstraint::Parameterized; | ||||
2 | |||||
3 | 3 | 21µs | 2 | 24µs | # spent 21µs (18+3) within Moose::Meta::TypeConstraint::Parameterized::BEGIN@3 which was called
# once (18µs+3µs) by Moose::Util::TypeConstraints::BEGIN@30 at line 3 # spent 21µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::BEGIN@3
# spent 3µs making 1 call to strict::import |
4 | 3 | 19µs | 2 | 25µs | # spent 16µs (7+9) within Moose::Meta::TypeConstraint::Parameterized::BEGIN@4 which was called
# once (7µs+9µs) by Moose::Util::TypeConstraints::BEGIN@30 at line 4 # spent 16µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::BEGIN@4
# spent 9µs making 1 call to warnings::import |
5 | 3 | 26µs | 2 | 192µs | # spent 99µs (6+93) within Moose::Meta::TypeConstraint::Parameterized::BEGIN@5 which was called
# once (6µs+93µs) by Moose::Util::TypeConstraints::BEGIN@30 at line 5 # spent 99µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::BEGIN@5
# spent 93µs making 1 call to metaclass::import |
6 | |||||
7 | 3 | 22µs | 2 | 54µs | # spent 30µs (6+24) within Moose::Meta::TypeConstraint::Parameterized::BEGIN@7 which was called
# once (6µs+24µs) by Moose::Util::TypeConstraints::BEGIN@30 at line 7 # spent 30µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::BEGIN@7
# spent 24µs making 1 call to Exporter::import |
8 | 3 | 30µs | 1 | 13µs | # spent 13µs within Moose::Meta::TypeConstraint::Parameterized::BEGIN@8 which was called
# once (13µs+0s) by Moose::Util::TypeConstraints::BEGIN@30 at line 8 # spent 13µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::BEGIN@8 |
9 | 3 | 133µs | 1 | 1.16ms | # spent 1.16ms (511µs+647µs) within Moose::Meta::TypeConstraint::Parameterized::BEGIN@9 which was called
# once (511µs+647µs) by Moose::Util::TypeConstraints::BEGIN@30 at line 9 # spent 1.16ms making 1 call to Moose::Meta::TypeConstraint::Parameterized::BEGIN@9 |
10 | |||||
11 | 1 | 700ns | our $VERSION = '0.98'; | ||
12 | 1 | 13µs | $VERSION = eval $VERSION; | ||
13 | 1 | 300ns | our $AUTHORITY = 'cpan:STEVAN'; | ||
14 | |||||
15 | 3 | 216µs | 2 | 82µs | # spent 44µs (7+38) within Moose::Meta::TypeConstraint::Parameterized::BEGIN@15 which was called
# once (7µs+38µs) by Moose::Util::TypeConstraints::BEGIN@30 at line 15 # spent 44µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::BEGIN@15
# spent 38µs making 1 call to base::import |
16 | |||||
17 | 1 | 3µs | 2 | 415µs | __PACKAGE__->meta->add_attribute('type_parameter' => ( # spent 398µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 16µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::meta |
18 | accessor => 'type_parameter', | ||||
19 | predicate => 'has_type_parameter', | ||||
20 | )); | ||||
21 | |||||
22 | sub equals { | ||||
23 | my ( $self, $type_or_name ) = @_; | ||||
24 | |||||
25 | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); | ||||
26 | |||||
27 | return unless $other->isa(__PACKAGE__); | ||||
28 | |||||
29 | return ( | ||||
30 | $self->type_parameter->equals( $other->type_parameter ) | ||||
31 | and | ||||
32 | $self->parent->equals( $other->parent ) | ||||
33 | ); | ||||
34 | } | ||||
35 | |||||
36 | sub compile_type_constraint { | ||||
37 | my $self = shift; | ||||
38 | |||||
39 | unless ( $self->has_type_parameter ) { | ||||
40 | require Moose; | ||||
41 | Moose->throw_error("You cannot create a Higher Order type without a type parameter"); | ||||
42 | } | ||||
43 | |||||
44 | my $type_parameter = $self->type_parameter; | ||||
45 | |||||
46 | unless ( blessed $type_parameter && $type_parameter->isa('Moose::Meta::TypeConstraint') ) { | ||||
47 | require Moose; | ||||
48 | Moose->throw_error("The type parameter must be a Moose meta type"); | ||||
49 | } | ||||
50 | |||||
51 | foreach my $type (Moose::Util::TypeConstraints::get_all_parameterizable_types()) { | ||||
52 | if (my $constraint = $type->generate_constraint_for($self)) { | ||||
53 | $self->_set_constraint($constraint); | ||||
54 | return $self->SUPER::compile_type_constraint; | ||||
55 | } | ||||
56 | } | ||||
57 | |||||
58 | # if we get here, then we couldn't | ||||
59 | # find a way to parameterize this type | ||||
60 | require Moose; | ||||
61 | Moose->throw_error("The " . $self->name . " constraint cannot be used, because " | ||||
62 | . $self->parent->name . " doesn't subtype or coerce from a parameterizable type."); | ||||
63 | } | ||||
64 | |||||
65 | sub create_child_type { | ||||
66 | my ($self, %opts) = @_; | ||||
67 | return Moose::Meta::TypeConstraint::Parameterizable->new(%opts, parent=>$self); | ||||
68 | } | ||||
69 | |||||
70 | 1 | 7µs | 1; | ||
71 | |||||
72 | __END__ | ||||
73 | |||||
74 | |||||
75 | =pod | ||||
76 | |||||
77 | =head1 NAME | ||||
78 | |||||
79 | Moose::Meta::TypeConstraint::Parameterized - Type constraints with a bound parameter (ArrayRef[Int]) | ||||
80 | |||||
81 | =head1 METHODS | ||||
82 | |||||
83 | This class is intentionally not documented because the API is | ||||
84 | confusing and needs some work. | ||||
85 | |||||
86 | =head1 INHERITANCE | ||||
87 | |||||
88 | C<Moose::Meta::TypeConstraint::Parameterized> is a subclass of | ||||
89 | L<Moose::Meta::TypeConstraint>. | ||||
90 | |||||
91 | =head1 BUGS | ||||
92 | |||||
93 | See L<Moose/BUGS> for details on reporting bugs. | ||||
94 | |||||
95 | =head1 AUTHOR | ||||
96 | |||||
97 | Stevan Little E<lt>stevan@iinteractive.comE<gt> | ||||
98 | |||||
99 | =head1 COPYRIGHT AND LICENSE | ||||
100 | |||||
101 | Copyright 2006-2010 by Infinity Interactive, Inc. | ||||
102 | |||||
103 | L<http://www.iinteractive.com> | ||||
104 | |||||
105 | This library is free software; you can redistribute it and/or modify | ||||
106 | it under the same terms as Perl itself. | ||||
107 | |||||
108 | =cut |