← Index
NYTProf Performance Profile   « block view • line view • sub view »
For -e
  Run on Wed Nov 17 21:45:08 2010
Reported on Wed Nov 17 22:10:09 2010

Filename/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/MooseX/Params/Validate.pm
StatementsExecuted 30 statements in 5.94ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1114.80ms22.2msMooseX::Params::Validate::::BEGIN@7MooseX::Params::Validate::BEGIN@7
1111.23ms4.79msMooseX::Params::Validate::::BEGIN@11MooseX::Params::Validate::BEGIN@11
111120µs145µsMooseX::Params::Validate::::BEGIN@3MooseX::Params::Validate::BEGIN@3
11179µs256µsMooseX::Params::Validate::::BEGIN@8MooseX::Params::Validate::BEGIN@8
11174µs2.09msMooseX::Params::Validate::::BEGIN@12MooseX::Params::Validate::BEGIN@12
11166µs166µsMooseX::Params::Validate::::BEGIN@4MooseX::Params::Validate::BEGIN@4
11165µs325µsMooseX::Params::Validate::::BEGIN@6MooseX::Params::Validate::BEGIN@6
11145µs2.71msMooseX::Params::Validate::::BEGIN@10MooseX::Params::Validate::BEGIN@10
0000s0sMooseX::Params::Validate::::__ANON__[:207]MooseX::Params::Validate::__ANON__[:207]
0000s0sMooseX::Params::Validate::::_cache_keyMooseX::Params::Validate::_cache_key
0000s0sMooseX::Params::Validate::::_caller_nameMooseX::Params::Validate::_caller_name
0000s0sMooseX::Params::Validate::::_convert_to_param_validate_specMooseX::Params::Validate::_convert_to_param_validate_spec
0000s0sMooseX::Params::Validate::::_is_tcMooseX::Params::Validate::_is_tc
0000s0sMooseX::Params::Validate::::pos_validated_listMooseX::Params::Validate::pos_validated_list
0000s0sMooseX::Params::Validate::::validated_hashMooseX::Params::Validate::validated_hash
0000s0sMooseX::Params::Validate::::validated_listMooseX::Params::Validate::validated_list
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package MooseX::Params::Validate;
2
33166µs2171µs
# spent 145µs (120+26) within MooseX::Params::Validate::BEGIN@3 which was called: # once (120µs+26µs) by Markdent::Role::HTMLStream::BEGIN@15 at line 3
use strict;
# spent 145µs making 1 call to MooseX::Params::Validate::BEGIN@3 # spent 26µs making 1 call to strict::import
43195µs2266µs
# spent 166µs (66+100) within MooseX::Params::Validate::BEGIN@4 which was called: # once (66µs+100µs) by Markdent::Role::HTMLStream::BEGIN@15 at line 4
use warnings;
# spent 166µs making 1 call to MooseX::Params::Validate::BEGIN@4 # spent 100µs making 1 call to warnings::import
5
63197µs2585µs
# spent 325µs (65+260) within MooseX::Params::Validate::BEGIN@6 which was called: # once (65µs+260µs) by Markdent::Role::HTMLStream::BEGIN@15 at line 6
use Carp 'confess';
# spent 325µs making 1 call to MooseX::Params::Validate::BEGIN@6 # spent 260µs making 1 call to Exporter::import
73747µs222.5ms
# spent 22.2ms (4.80+17.4) within MooseX::Params::Validate::BEGIN@7 which was called: # once (4.80ms+17.4ms) by Markdent::Role::HTMLStream::BEGIN@15 at line 7
use Devel::Caller 'caller_cv';
# spent 22.2ms making 1 call to MooseX::Params::Validate::BEGIN@7 # spent 294µs making 1 call to Exporter::import
83128µs2432µs
# spent 256µs (79+177) within MooseX::Params::Validate::BEGIN@8 which was called: # once (79µs+177µs) by Markdent::Role::HTMLStream::BEGIN@15 at line 8
use Scalar::Util 'blessed', 'refaddr';
# spent 256µs making 1 call to MooseX::Params::Validate::BEGIN@8 # spent 177µs making 1 call to Exporter::import
9
103149µs25.37ms
# spent 2.71ms (45µs+2.66) within MooseX::Params::Validate::BEGIN@10 which was called: # once (45µs+2.66ms) by Markdent::Role::HTMLStream::BEGIN@15 at line 10
use Moose::Util::TypeConstraints qw( find_type_constraint class_type role_type );
# spent 2.71ms making 1 call to MooseX::Params::Validate::BEGIN@10 # spent 2.66ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:456]
113583µs14.79ms
# spent 4.79ms (1.23+3.56) within MooseX::Params::Validate::BEGIN@11 which was called: # once (1.23ms+3.56ms) by Markdent::Role::HTMLStream::BEGIN@15 at line 11
use Params::Validate ();
# spent 4.79ms making 1 call to MooseX::Params::Validate::BEGIN@11
1212.02ms
# spent 2.09ms (74µs+2.02) within MooseX::Params::Validate::BEGIN@12 which was called: # once (74µs+2.02ms) by Markdent::Role::HTMLStream::BEGIN@15 at line 20
use Sub::Exporter -setup => {
# spent 2.02ms making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756]
13 exports => [
14 qw( validated_hash validated_list pos_validated_list validate validatep )
15 ],
16 groups => {
17 default => [qw( validated_hash validated_list pos_validated_list )],
18 deprecated => [qw( validate validatep )],
19 },
2033.73ms12.09ms};
# spent 2.09ms making 1 call to MooseX::Params::Validate::BEGIN@12
21
2216µsour $VERSION = '0.14';
2314µsour $AUTHORITY = 'cpan:STEVAN';
24
2513µsmy %CACHED_SPECS;
26
27sub validated_hash {
28 my ( $args, %spec ) = @_;
29
30 my $cache_key = _cache_key( \%spec );
31
32 if ( exists $CACHED_SPECS{$cache_key} ) {
33 ( ref $CACHED_SPECS{$cache_key} eq 'HASH' )
34 || confess
35 "I was expecting a HASH-ref in the cached $cache_key parameter"
36 . " spec, you are doing something funky, stop it!";
37 %spec = %{ $CACHED_SPECS{$cache_key} };
38 }
39 else {
40 my $should_cache = delete $spec{MX_PARAMS_VALIDATE_NO_CACHE} ? 0 : 1;
41
42 $spec{$_} = _convert_to_param_validate_spec( $spec{$_} )
43 foreach keys %spec;
44
45 $CACHED_SPECS{$cache_key} = \%spec
46 if $should_cache;
47 }
48
49 my $instance;
50 $instance = shift @$args if blessed $args->[0];
51
52 my %args = @$args;
53
54 $args{$_} = $spec{$_}{constraint}->coerce( $args{$_} )
55 for grep { $spec{$_}{coerce} && exists $args{$_} } keys %spec;
56
57 %args = Params::Validate::validate_with(
58 params => \%args,
59 spec => \%spec,
60 called => _caller_name(),
61 );
62
63 return ( ( defined $instance ? $instance : () ), %args );
64}
65
6619µs*validate = \&validated_hash;
67
68sub validated_list {
69 my ( $args, @spec ) = @_;
70
71 my %spec = @spec;
72
73 my $cache_key = _cache_key( \%spec );
74
75 my @ordered_spec;
76 if ( exists $CACHED_SPECS{$cache_key} ) {
77 ( ref $CACHED_SPECS{$cache_key} eq 'ARRAY' )
78 || confess
79 "I was expecting a ARRAY-ref in the cached $cache_key parameter"
80 . " spec, you are doing something funky, stop it!";
81 %spec = %{ $CACHED_SPECS{$cache_key}->[0] };
82 @ordered_spec = @{ $CACHED_SPECS{$cache_key}->[1] };
83 }
84 else {
85 my $should_cache = delete $spec{MX_PARAMS_VALIDATE_NO_CACHE} ? 0 : 1;
86
87 @ordered_spec = grep { exists $spec{$_} } @spec;
88
89 $spec{$_} = _convert_to_param_validate_spec( $spec{$_} )
90 foreach keys %spec;
91
92 $CACHED_SPECS{$cache_key} = [ \%spec, \@ordered_spec ]
93 if $should_cache;
94 }
95
96 my $instance;
97 $instance = shift @$args if blessed $args->[0];
98
99 my %args = @$args;
100
101 $args{$_} = $spec{$_}{constraint}->coerce( $args{$_} )
102 for grep { $spec{$_}{coerce} && exists $args{$_} } keys %spec;
103
104 %args = Params::Validate::validate_with(
105 params => \%args,
106 spec => \%spec,
107 called => _caller_name(),
108 );
109
110 return (
111 ( defined $instance ? $instance : () ),
112 @args{@ordered_spec}
113 );
114}
115
11614µs*validatep = \&validated_list;
117
118sub pos_validated_list {
119 my $args = shift;
120
121 my @spec;
122 push @spec, shift while ref $_[0];
123
124 my %extra = @_;
125
126 my $cache_key = _cache_key( \%extra );
127
128 my @pv_spec;
129 if ( exists $CACHED_SPECS{$cache_key} ) {
130 ( ref $CACHED_SPECS{$cache_key} eq 'ARRAY' )
131 || confess
132 "I was expecting an ARRAY-ref in the cached $cache_key parameter"
133 . " spec, you are doing something funky, stop it!";
134 @pv_spec = @{ $CACHED_SPECS{$cache_key} };
135 }
136 else {
137 my $should_cache = exists $extra{MX_PARAMS_VALIDATE_NO_CACHE} ? 0 : 1;
138
139 # prepare the parameters ...
140 @pv_spec = map { _convert_to_param_validate_spec($_) } @spec;
141
142 $CACHED_SPECS{$cache_key} = \@pv_spec
143 if $should_cache;
144 }
145
146 my @args = @{$args};
147
148 $args[$_] = $pv_spec[$_]{constraint}->coerce( $args[$_] )
149 for grep { $pv_spec[$_] && $pv_spec[$_]{coerce} } 0 .. $#args;
150
151 @args = Params::Validate::validate_with(
152 params => \@args,
153 spec => \@pv_spec,
154 called => _caller_name(),
155 );
156
157 return @args;
158}
159
160sub _cache_key {
161 my $spec = shift;
162
163 if ( exists $spec->{MX_PARAMS_VALIDATE_CACHE_KEY} ) {
164 return delete $spec->{MX_PARAMS_VALIDATE_CACHE_KEY};
165 }
166 else {
167 return refaddr( caller_cv(2) );
168 }
169}
170
171sub _convert_to_param_validate_spec {
172 my ($spec) = @_;
173 my %pv_spec;
174
175 $pv_spec{optional} = $spec->{optional}
176 if exists $spec->{optional};
177
178 $pv_spec{default} = $spec->{default}
179 if exists $spec->{default};
180
181 $pv_spec{coerce} = $spec->{coerce}
182 if exists $spec->{coerce};
183
184 my $constraint;
185 if ( defined $spec->{isa} ) {
186 $constraint
187 = _is_tc( $spec->{isa} )
188 || Moose::Util::TypeConstraints::find_or_parse_type_constraint(
189 $spec->{isa} )
190 || class_type( $spec->{isa} );
191 }
192 elsif ( defined $spec->{does} ) {
193 $constraint
194 = _is_tc( $spec->{isa} )
195 || find_type_constraint( $spec->{does} )
196 || role_type( $spec->{does} );
197 }
198
199 $pv_spec{callbacks} = $spec->{callbacks}
200 if exists $spec->{callbacks};
201
202 if ($constraint) {
203 $pv_spec{constraint} = $constraint;
204
205 $pv_spec{callbacks}
206 { 'checking type constraint for ' . $constraint->name }
207 = sub { $constraint->check( $_[0] ) };
208 }
209
210 delete $pv_spec{coerce}
211 unless $pv_spec{constraint} && $pv_spec{constraint}->has_coercion;
212
213 return \%pv_spec;
214}
215
216sub _is_tc {
217 my $maybe_tc = shift;
218
219 return $maybe_tc
220 if defined $maybe_tc
221 && blessed $maybe_tc
222 && $maybe_tc->isa('Moose::Meta::TypeConstraint');
223}
224
225sub _caller_name {
226 my $depth = shift || 0;
227
228 return ( caller( 2 + $depth ) )[3];
229}
230
231125µs1;
232
233__END__