Profile of /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/TypeConstraint/Parameterizable.pm

← Index
NYTProf Performance Profile «block view•line view•sub view»
For 01.HTTP.t
Run on Tue May 4 15:25:55 2010
Reported on Tue May 4 15:26:24 2010

File | /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/TypeConstraint/Parameterizable.pm
Statements Executed | 23
Statement Execution Time | 454µs

Subroutines — ordered by exclusive time
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 14µs | 17µs | Moose::Meta::TypeConstraint::Parameterizable::::BEGIN@3Moose::Meta::TypeConstraint::Parameterizable::BEGIN@3
1 | 1 | 1 | 11µs | 11µs | Moose::Meta::TypeConstraint::Parameterizable::::BEGIN@12Moose::Meta::TypeConstraint::Parameterizable::BEGIN@12
1 | 1 | 1 | 7µs | 88µs | Moose::Meta::TypeConstraint::Parameterizable::::BEGIN@11Moose::Meta::TypeConstraint::Parameterizable::BEGIN@11
1 | 1 | 1 | 7µs | 16µs | Moose::Meta::TypeConstraint::Parameterizable::::BEGIN@4Moose::Meta::TypeConstraint::Parameterizable::BEGIN@4
1 | 1 | 1 | 6µs | 98µs | Moose::Meta::TypeConstraint::Parameterizable::::BEGIN@5Moose::Meta::TypeConstraint::Parameterizable::BEGIN@5
1 | 1 | 1 | 3µs | 3µs | Moose::Meta::TypeConstraint::Parameterizable::::BEGIN@13Moose::Meta::TypeConstraint::Parameterizable::BEGIN@13
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Parameterizable::::__ANON__[:42]Moose::Meta::TypeConstraint::Parameterizable::__ANON__[:42]
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::::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 |  |  |  |  |
3 | 3 | 21µs | 2 | 20µs | # spent 17µs (14+3) within Moose::Meta::TypeConstraint::Parameterizable::BEGIN@3 which was called # once (14µs+3µs) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@9 at line 3 use strict; # spent 17µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::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::Parameterizable::BEGIN@4 which was called # once (7µs+9µs) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@9 at line 4 use warnings; # spent 16µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@4 # spent 9µs making 1 call to warnings::import
5 | 3 | 52µs | 2 | 190µs | # spent 98µs (6+92) within Moose::Meta::TypeConstraint::Parameterizable::BEGIN@5 which was called # once (6µs+92µs) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@9 at line 5 use metaclass; # spent 98µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@5 # spent 92µs making 1 call to metaclass::import
6 |  |  |  |  |
7 | 1 | 700ns |  |  | our $VERSION = '0.98';
8 | 1 | 18µs |  |  | $VERSION = eval $VERSION;
9 | 1 | 300ns |  |  | our $AUTHORITY = 'cpan:STEVAN';
10 |  |  |  |  |
11 | 3 | 24µs | 2 | 169µs | # spent 88µs (7+81) within Moose::Meta::TypeConstraint::Parameterizable::BEGIN@11 which was called # once (7µs+81µs) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@9 at line 11 use base 'Moose::Meta::TypeConstraint'; # spent 88µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@11 # spent 81µs making 1 call to base::import
12 | 3 | 27µs | 1 | 11µs | # spent 11µs within Moose::Meta::TypeConstraint::Parameterizable::BEGIN@12 which was called # once (11µs+0s) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@9 at line 12 use Moose::Meta::TypeConstraint::Parameterized; # spent 11µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@12
13 | 3 | 276µs | 1 | 3µs | # spent 3µs within Moose::Meta::TypeConstraint::Parameterizable::BEGIN@13 which was called # once (3µs+0s) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@9 at line 13 use Moose::Util::TypeConstraints (); # spent 3µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@13
14 |  |  |  |  |
15 | 1 | 3µs | 2 | 414µs | __PACKAGE__->meta->add_attribute('constraint_generator' => ( # spent 397µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 17µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::meta
16 |  |  |  |  | accessor => 'constraint_generator',
17 |  |  |  |  | predicate => 'has_constraint_generator',
18 |  |  |  |  | ));
19 |  |  |  |  |
20 |  |  |  |  | sub generate_constraint_for {
21 |  |  |  |  | my ($self, $type) = @_;
22 |  |  |  |  |
23 |  |  |  |  | return unless $self->has_constraint_generator;
24 |  |  |  |  |
25 |  |  |  |  | return $self->constraint_generator->($type->type_parameter)
26 |  |  |  |  | if $type->is_subtype_of($self->name);
27 |  |  |  |  |
28 |  |  |  |  | return $self->_can_coerce_constraint_from($type)
29 |  |  |  |  | if $self->has_coercion
30 |  |  |  |  | && $self->coercion->has_coercion_for_type($type->parent->name);
31 |  |  |  |  |
32 |  |  |  |  | return;
33 |  |  |  |  | }
34 |  |  |  |  |
35 |  |  |  |  | sub _can_coerce_constraint_from {
36 |  |  |  |  | my ($self, $type) = @_;
37 |  |  |  |  | my $coercion = $self->coercion;
38 |  |  |  |  | my $constraint = $self->constraint_generator->($type->type_parameter);
39 |  |  |  |  | return sub {
40 |  |  |  |  | local $_ = $coercion->coerce($_);
41 |  |  |  |  | $constraint->(@_);
42 |  |  |  |  | };
43 |  |  |  |  | }
44 |  |  |  |  |
45 |  |  |  |  | sub _parse_type_parameter {
46 |  |  |  |  | my ($self, $type_parameter) = @_;
47 |  |  |  |  | return Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($type_parameter);
48 |  |  |  |  | }
49 |  |  |  |  |
50 |  |  |  |  | sub parameterize {
51 |  |  |  |  | my ($self, $type_parameter) = @_;
52 |  |  |  |  |
53 |  |  |  |  | my $contained_tc = $self->_parse_type_parameter($type_parameter);
54 |  |  |  |  |
55 |  |  |  |  | ## The type parameter should be a subtype of the parent's type parameter
56 |  |  |  |  | ## if there is one.
57 |  |  |  |  |
58 |  |  |  |  | if(my $parent = $self->parent) {
59 |  |  |  |  | if($parent->can('type_parameter')) {
60 |  |  |  |  | unless ( $contained_tc->is_a_type_of($parent->type_parameter) ) {
61 |  |  |  |  | require Moose;
62 |  |  |  |  | Moose->throw_error("$type_parameter is not a subtype of ".$parent->type_parameter);
63 |  |  |  |  | }
64 |  |  |  |  | }
65 |  |  |  |  | }
66 |  |  |  |  |
67 |  |  |  |  | if ( $contained_tc->isa('Moose::Meta::TypeConstraint') ) {
68 |  |  |  |  | my $tc_name = $self->name . '[' . $contained_tc->name . ']';
69 |  |  |  |  | return Moose::Meta::TypeConstraint::Parameterized->new(
70 |  |  |  |  | name => $tc_name,
71 |  |  |  |  | parent => $self,
72 |  |  |  |  | type_parameter => $contained_tc,
73 |  |  |  |  | );
74 |  |  |  |  | }
75 |  |  |  |  | else {
76 |  |  |  |  | require Moose;
77 |  |  |  |  | Moose->throw_error("The type parameter must be a Moose meta type");
78 |  |  |  |  | }
79 |  |  |  |  | }
80 |  |  |  |  |
81 |  |  |  |  |
82 | 1 | 14µs |  |  | 1;
83 |  |  |  |  |
84 |  |  |  |  | __END__
85 |  |  |  |  |
86 |  |  |  |  |
87 |  |  |  |  | =pod
88 |  |  |  |  |
89 |  |  |  |  | =head1 NAME
90 |  |  |  |  |
91 |  |  |  |  | Moose::Meta::TypeConstraint::Parameterizable - Type constraints which can take a parameter (ArrayRef)
92 |  |  |  |  |
93 |  |  |  |  | =head1 DESCRIPTION
94 |  |  |  |  |
95 |  |  |  |  | This class represents a parameterizable type constraint. This is a
96 |  |  |  |  | type constraint like C<ArrayRef> or C<HashRef>, that can be
97 |  |  |  |  | parameterized and made more specific by specifying a contained
98 |  |  |  |  | type. For example, instead of just an C<ArrayRef> of anything, you can
99 |  |  |  |  | specify that is an C<ArrayRef[Int]>.
100 |  |  |  |  |
101 |  |  |  |  | A parameterizable constraint should not be used as an attribute type
102 |  |  |  |  | constraint. Instead, when parameterized it creates a
103 |  |  |  |  | L<Moose::Meta::TypeConstraint::Parameterized> which should be used.
104 |  |  |  |  |
105 |  |  |  |  | =head1 INHERITANCE
106 |  |  |  |  |
107 |  |  |  |  | C<Moose::Meta::TypeConstraint::Parameterizable> is a subclass of
108 |  |  |  |  | L<Moose::Meta::TypeConstraint>.
109 |  |  |  |  |
110 |  |  |  |  | =head1 METHODS
111 |  |  |  |  |
112 |  |  |  |  | This class is intentionally not documented because the API is
113 |  |  |  |  | confusing and needs some work.
114 |  |  |  |  |
115 |  |  |  |  | =head1 BUGS
116 |  |  |  |  |
117 |  |  |  |  | See L<Moose/BUGS> for details on reporting bugs.
118 |  |  |  |  |
119 |  |  |  |  | =head1 AUTHOR
120 |  |  |  |  |
121 |  |  |  |  | Stevan Little E<lt>stevan@iinteractive.comE<gt>
122 |  |  |  |  |
123 |  |  |  |  | =head1 COPYRIGHT AND LICENSE
124 |  |  |  |  |
125 |  |  |  |  | Copyright 2006-2010 by Infinity Interactive, Inc.
126 |  |  |  |  |
127 |  |  |  |  | L<http://www.iinteractive.com>
128 |  |  |  |  |
129 |  |  |  |  | This library is free software; you can redistribute it and/or modify
130 |  |  |  |  | it under the same terms as Perl itself.
131 |  |  |  |  |
132 |  |  |  |  | =cut