Profile of Moose/Meta/TypeConstraint/Parameterizable.pm

← Index
NYTProf Performance Profile «block view•line view•sub view»
For xt/tapper-mcp-scheduler-with-db-longrun.t
Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:22:35 2012

Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/TypeConstraint/Parameterizable.pm
Statements | Executed 27 statements in 593µs

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 9µs | 9µs | Moose::Meta::TypeConstraint::Parameterizable::::BEGIN@14Moose::Meta::TypeConstraint::Parameterizable::BEGIN@14
1 | 1 | 1 | 9µs | 9µs | Moose::Meta::TypeConstraint::Parameterizable::::BEGIN@2Moose::Meta::TypeConstraint::Parameterizable::BEGIN@2
1 | 1 | 1 | 8µs | 88µs | Moose::Meta::TypeConstraint::Parameterizable::::BEGIN@13Moose::Meta::TypeConstraint::Parameterizable::BEGIN@13
1 | 1 | 1 | 8µs | 37µs | Moose::Meta::TypeConstraint::Parameterizable::::BEGIN@17Moose::Meta::TypeConstraint::Parameterizable::BEGIN@17
1 | 1 | 1 | 7µs | 19µs | Moose::Meta::TypeConstraint::Parameterizable::::BEGIN@10Moose::Meta::TypeConstraint::Parameterizable::BEGIN@10
1 | 1 | 1 | 7µs | 10µs | Moose::Meta::TypeConstraint::Parameterizable::::BEGIN@9Moose::Meta::TypeConstraint::Parameterizable::BEGIN@9
1 | 1 | 1 | 6µs | 460µs | Moose::Meta::TypeConstraint::Parameterizable::::BEGIN@11Moose::Meta::TypeConstraint::Parameterizable::BEGIN@11
1 | 1 | 1 | 4µs | 4µs | Moose::Meta::TypeConstraint::Parameterizable::::BEGIN@15Moose::Meta::TypeConstraint::Parameterizable::BEGIN@15
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Parameterizable::::__ANON__[:53]Moose::Meta::TypeConstraint::Parameterizable::__ANON__[:53]
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Parameterizable::::_can_coerce_constraint_fromMoose::Meta::TypeConstraint::Parameterizable::_can_coerce_constraint_from
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Parameterizable::::_parse_type_parameterMoose::Meta::TypeConstraint::Parameterizable::_parse_type_parameter
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Parameterizable::::generate_constraint_forMoose::Meta::TypeConstraint::Parameterizable::generate_constraint_for
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Parameterizable::::generate_inline_forMoose::Meta::TypeConstraint::Parameterizable::generate_inline_for
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Parameterizable::::parameterizeMoose::Meta::TypeConstraint::Parameterizable::parameterize

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | package Moose::Meta::TypeConstraint::Parameterizable;
2 |  |  |  |  | # spent 9µs within Moose::Meta::TypeConstraint::Parameterizable::BEGIN@2 which was called: # once (9µs+0s) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@15 at line 4 BEGIN {
3 | 1 | 5µs |  |  | $Moose::Meta::TypeConstraint::Parameterizable::AUTHORITY = 'cpan:STEVAN';
4 | 1 | 24µs | 1 | 9µs | } # spent 9µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@2
5 |  |  |  |  | {
6 | 2 | 1µs |  |  | $Moose::Meta::TypeConstraint::Parameterizable::VERSION = '2.0602';
7 |  |  |  |  | }
8 |  |  |  |  |
9 | 3 | 16µs | 2 | 13µs | # spent 10µs (7+3) within Moose::Meta::TypeConstraint::Parameterizable::BEGIN@9 which was called: # once (7µs+3µs) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@15 at line 9 use strict; # spent 10µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@9 # spent 3µs making 1 call to strict::import
10 | 3 | 20µs | 2 | 32µs | # spent 19µs (7+12) within Moose::Meta::TypeConstraint::Parameterizable::BEGIN@10 which was called: # once (7µs+12µs) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@15 at line 10 use warnings; # spent 19µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@10 # spent 12µs making 1 call to warnings::import
11 | 3 | 24µs | 2 | 913µs | # spent 460µs (6+453) within Moose::Meta::TypeConstraint::Parameterizable::BEGIN@11 which was called: # once (6µs+453µs) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@15 at line 11 use metaclass; # spent 460µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@11 # spent 454µs making 1 call to metaclass::import
12 |  |  |  |  |
13 | 3 | 21µs | 2 | 167µs | # spent 88µs (8+79) within Moose::Meta::TypeConstraint::Parameterizable::BEGIN@13 which was called: # once (8µs+79µs) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@15 at line 13 use base 'Moose::Meta::TypeConstraint'; # spent 88µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@13 # spent 79µs making 1 call to base::import
14 | 3 | 22µ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 use Moose::Meta::TypeConstraint::Parameterized; # spent 9µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@14
15 | 3 | 17µ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 use Moose::Util::TypeConstraints (); # spent 4µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@15
16 |  |  |  |  |
17 | 3 | 424µs | 2 | 66µs | # spent 37µs (8+29) within Moose::Meta::TypeConstraint::Parameterizable::BEGIN@17 which was called: # once (8µs+29µs) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@15 at line 17 use Carp 'confess'; # spent 37µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@17 # spent 29µs making 1 call to Exporter::import
18 |  |  |  |  |
19 | 1 | 6µs | 3 | 649µs | __PACKAGE__->meta->add_attribute('constraint_generator' => ( # spent 616µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 23µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::meta # spent 9µ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 | 450µs | __PACKAGE__->meta->add_attribute('inline_generator' => ( # spent 434µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 11µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::meta # spent 6µ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 | 9µs |  |  | 1;
105 |  |  |  |  |
106 |  |  |  |  | # ABSTRACT: Type constraints which can take a parameter (ArrayRef)
107 |  |  |  |  |
- - |  |  |  |  |
110 |  |  |  |  | =pod
111 |  |  |  |  |
112 |  |  |  |  | =head1 NAME
113 |  |  |  |  |
114 |  |  |  |  | Moose::Meta::TypeConstraint::Parameterizable - Type constraints which can take a parameter (ArrayRef)
115 |  |  |  |  |
116 |  |  |  |  | =head1 VERSION
117 |  |  |  |  |
118 |  |  |  |  | version 2.0602
119 |  |  |  |  |
120 |  |  |  |  | =head1 DESCRIPTION
121 |  |  |  |  |
122 |  |  |  |  | This class represents a parameterizable type constraint. This is a
123 |  |  |  |  | type constraint like C<ArrayRef> or C<HashRef>, that can be
124 |  |  |  |  | parameterized and made more specific by specifying a contained
125 |  |  |  |  | type. For example, instead of just an C<ArrayRef> of anything, you can
126 |  |  |  |  | specify that is an C<ArrayRef[Int]>.
127 |  |  |  |  |
128 |  |  |  |  | A parameterizable constraint should not be used as an attribute type
129 |  |  |  |  | constraint. Instead, when parameterized it creates a
130 |  |  |  |  | L<Moose::Meta::TypeConstraint::Parameterized> which should be used.
131 |  |  |  |  |
132 |  |  |  |  | =head1 INHERITANCE
133 |  |  |  |  |
134 |  |  |  |  | C<Moose::Meta::TypeConstraint::Parameterizable> is a subclass of
135 |  |  |  |  | L<Moose::Meta::TypeConstraint>.
136 |  |  |  |  |
137 |  |  |  |  | =head1 METHODS
138 |  |  |  |  |
139 |  |  |  |  | This class is intentionally not documented because the API is
140 |  |  |  |  | confusing and needs some work.
141 |  |  |  |  |
142 |  |  |  |  | =head1 BUGS
143 |  |  |  |  |
144 |  |  |  |  | See L<Moose/BUGS> for details on reporting bugs.
145 |  |  |  |  |
146 |  |  |  |  | =head1 AUTHOR
147 |  |  |  |  |
148 |  |  |  |  | Moose is maintained by the Moose Cabal, along with the help of many contributors. See L<Moose/CABAL> and L<Moose/CONTRIBUTORS> for details.
149 |  |  |  |  |
150 |  |  |  |  | =head1 COPYRIGHT AND LICENSE
151 |  |  |  |  |
152 |  |  |  |  | This software is copyright (c) 2012 by Infinity Interactive, Inc..
153 |  |  |  |  |
154 |  |  |  |  | This is free software; you can redistribute it and/or modify it under
155 |  |  |  |  | the same terms as the Perl 5 programming language system itself.
156 |  |  |  |  |
157 |  |  |  |  | =cut
158 |  |  |  |  |
159 |  |  |  |  |
160 |  |  |  |  | __END__