← Index
NYTProf Performance Profile   « line view »
For fastest.pl
  Run on Fri Jan 31 20:48:16 2014
Reported on Fri Jan 31 20:49:41 2014

Filename/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Meta/TypeConstraint/Parameterizable.pm
StatementsExecuted 20 statements in 860µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11115µs19µsMoose::Meta::TypeConstraint::Parameterizable::::BEGIN@10Moose::Meta::TypeConstraint::Parameterizable::BEGIN@10
11111µs11µsMoose::Meta::TypeConstraint::Parameterizable::::BEGIN@2Moose::Meta::TypeConstraint::Parameterizable::BEGIN@2
1119µs90µsMoose::Meta::TypeConstraint::Parameterizable::::BEGIN@13Moose::Meta::TypeConstraint::Parameterizable::BEGIN@13
1119µs9µsMoose::Meta::TypeConstraint::Parameterizable::::BEGIN@14Moose::Meta::TypeConstraint::Parameterizable::BEGIN@14
1119µs38µsMoose::Meta::TypeConstraint::Parameterizable::::BEGIN@17Moose::Meta::TypeConstraint::Parameterizable::BEGIN@17
1118µs493µsMoose::Meta::TypeConstraint::Parameterizable::::BEGIN@11Moose::Meta::TypeConstraint::Parameterizable::BEGIN@11
1118µs23µsMoose::Meta::TypeConstraint::Parameterizable::::BEGIN@9Moose::Meta::TypeConstraint::Parameterizable::BEGIN@9
1114µs4µsMoose::Meta::TypeConstraint::Parameterizable::::BEGIN@15Moose::Meta::TypeConstraint::Parameterizable::BEGIN@15
0000s0sMoose::Meta::TypeConstraint::Parameterizable::::__ANON__[:53]Moose::Meta::TypeConstraint::Parameterizable::__ANON__[:53]
0000s0sMoose::Meta::TypeConstraint::Parameterizable::::_can_coerce_constraint_fromMoose::Meta::TypeConstraint::Parameterizable::_can_coerce_constraint_from
0000s0sMoose::Meta::TypeConstraint::Parameterizable::::_parse_type_parameterMoose::Meta::TypeConstraint::Parameterizable::_parse_type_parameter
0000s0sMoose::Meta::TypeConstraint::Parameterizable::::generate_constraint_forMoose::Meta::TypeConstraint::Parameterizable::generate_constraint_for
0000s0sMoose::Meta::TypeConstraint::Parameterizable::::generate_inline_forMoose::Meta::TypeConstraint::Parameterizable::generate_inline_for
0000s0sMoose::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
1package 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
BEGIN {
317µs $Moose::Meta::TypeConstraint::Parameterizable::AUTHORITY = 'cpan:STEVAN';
4149µs111µs}
5{
621µs $Moose::Meta::TypeConstraint::Parameterizable::VERSION = '2.1005';
7}
8
9230µs238µ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
use strict;
# spent 23µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@9 # spent 15µs making 1 call to strict::import
10230µs224µ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
use warnings;
# spent 19µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@10 # spent 4µs making 1 call to warnings::import
11240µs2978µ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
use metaclass;
# spent 493µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@11 # spent 485µs making 1 call to metaclass::import
12
13241µs2170µ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
use base 'Moose::Meta::TypeConstraint';
# spent 90µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@13 # spent 80µs making 1 call to base::import
14233µs19µ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;
15231µs14µ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 ();
16
172580µs267µ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
use Carp 'confess';
# spent 38µs making 1 call to Moose::Meta::TypeConstraint::Parameterizable::BEGIN@17 # spent 29µs making 1 call to Exporter::import
18
1915µs3643µ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
2514µs3619µ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
31sub 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
46sub _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
56sub 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
66sub _parse_type_parameter {
67 my ($self, $type_parameter) = @_;
68 return Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($type_parameter);
69}
70
71sub 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
10418µs1;
105
106# ABSTRACT: Type constraints which can take a parameter (ArrayRef)
107
108__END__