← Index
NYTProf Performance Profile   « line view »
For svc/members/upsert
  Run on Tue Jan 13 11:50:22 2015
Reported on Tue Jan 13 12:09:49 2015

Filename/usr/share/perl5/DateTime/Format/Builder.pm
StatementsExecuted 88 statements in 1.90ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11155µs1.48msDateTime::Format::Builder::::create_classDateTime::Format::Builder::create_class
31120µs1.37msDateTime::Format::Builder::::create_parserDateTime::Format::Builder::create_parser
11116µs66µsDateTime::Format::Builder::::BEGIN@12DateTime::Format::Builder::BEGIN@12
11115µs15µsDateTime::Format::Builder::::BEGIN@9DateTime::Format::Builder::BEGIN@9
31115µs1.39msDateTime::Format::Builder::::create_end_parserDateTime::Format::Builder::create_end_parser
11111µs22µsDateTime::Format::Builder::::BEGIN@6DateTime::Format::Builder::BEGIN@6
11111µs22µsDateTime::Format::Builder::::BEGIN@11DateTime::Format::Builder::BEGIN@11
11111µs11µsDateTime::Format::Builder::::create_constructorDateTime::Format::Builder::create_constructor
11110µs18µsDateTime::Format::Builder::::BEGIN@7DateTime::Format::Builder::BEGIN@7
3117µs7µsDateTime::Format::Builder::::create_methodDateTime::Format::Builder::create_method
1117µs37µsDateTime::Format::Builder::::BEGIN@10DateTime::Format::Builder::BEGIN@10
1116µs24µsDateTime::Format::Builder::::BEGIN@15DateTime::Format::Builder::BEGIN@15
1116µs1.48msDateTime::Format::Builder::::importDateTime::Format::Builder::import
1116µs15µsDateTime::Format::Builder::::BEGIN@50DateTime::Format::Builder::BEGIN@50
1116µs14µsDateTime::Format::Builder::::BEGIN@96DateTime::Format::Builder::BEGIN@96
0000s0sDateTime::Format::Builder::::__ANON__[:109]DateTime::Format::Builder::__ANON__[:109]
0000s0sDateTime::Format::Builder::::__ANON__[:140]DateTime::Format::Builder::__ANON__[:140]
0000s0sDateTime::Format::Builder::::__ANON__[:161]DateTime::Format::Builder::__ANON__[:161]
0000s0sDateTime::Format::Builder::::cloneDateTime::Format::Builder::clone
0000s0sDateTime::Format::Builder::::format_datetimeDateTime::Format::Builder::format_datetime
0000s0sDateTime::Format::Builder::::get_parserDateTime::Format::Builder::get_parser
0000s0sDateTime::Format::Builder::::newDateTime::Format::Builder::new
0000s0sDateTime::Format::Builder::::on_failDateTime::Format::Builder::on_fail
0000s0sDateTime::Format::Builder::::parse_datetimeDateTime::Format::Builder::parse_datetime
0000s0sDateTime::Format::Builder::::parserDateTime::Format::Builder::parser
0000s0sDateTime::Format::Builder::::set_parserDateTime::Format::Builder::set_parser
0000s0sDateTime::Format::Builder::::verboseDateTime::Format::Builder::verbose
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package DateTime::Format::Builder;
2{
321µs $DateTime::Format::Builder::VERSION = '0.81';
4}
5
6224µs233µs
# spent 22µs (11+11) within DateTime::Format::Builder::BEGIN@6 which was called: # once (11µs+11µs) by DateTime::Format::MySQL::BEGIN@11 at line 6
use strict;
# spent 22µs making 1 call to DateTime::Format::Builder::BEGIN@6 # spent 11µs making 1 call to strict::import
7222µs226µs
# spent 18µs (10+8) within DateTime::Format::Builder::BEGIN@7 which was called: # once (10µs+8µs) by DateTime::Format::MySQL::BEGIN@11 at line 7
use warnings;
# spent 18µs making 1 call to DateTime::Format::Builder::BEGIN@7 # spent 8µs making 1 call to warnings::import
8
9242µs115µs
# spent 15µs within DateTime::Format::Builder::BEGIN@9 which was called: # once (15µs+0s) by DateTime::Format::MySQL::BEGIN@11 at line 9
use 5.005;
# spent 15µs making 1 call to DateTime::Format::Builder::BEGIN@9
10224µs266µs
# spent 37µs (7+29) within DateTime::Format::Builder::BEGIN@10 which was called: # once (7µs+29µs) by DateTime::Format::MySQL::BEGIN@11 at line 10
use Carp;
# spent 37µs making 1 call to DateTime::Format::Builder::BEGIN@10 # spent 29µs making 1 call to Exporter::import
11351µs234µs
# spent 22µs (11+12) within DateTime::Format::Builder::BEGIN@11 which was called: # once (11µs+12µs) by DateTime::Format::MySQL::BEGIN@11 at line 11
use DateTime 1.00;
# spent 22µs making 1 call to DateTime::Format::Builder::BEGIN@11 # spent 12µs making 1 call to version::_VERSION
1214µs144µs
# spent 66µs (16+51) within DateTime::Format::Builder::BEGIN@12 which was called: # once (16µs+51µs) by DateTime::Format::MySQL::BEGIN@11 at line 14
use Params::Validate 0.72 qw(
# spent 44µs making 1 call to Exporter::import
13 validate SCALAR ARRAYREF HASHREF SCALARREF CODEREF GLOB GLOBREF UNDEF
14237µs273µs);
# spent 66µs making 1 call to DateTime::Format::Builder::BEGIN@12 # spent 6µs making 1 call to version::_VERSION
152158µs241µs
# spent 24µs (6+17) within DateTime::Format::Builder::BEGIN@15 which was called: # once (6µs+17µs) by DateTime::Format::MySQL::BEGIN@11 at line 15
use vars qw( %dispatch_data );
# spent 24µs making 1 call to DateTime::Format::Builder::BEGIN@15 # spent 17µs making 1 call to vars::import
16
171200nsmy $parser = 'DateTime::Format::Builder::Parser';
18
19sub verbose {
20 warn "Use of verbose() deprecated for the interim.";
21 1;
22}
23
24
# spent 1.48ms (6µs+1.48) within DateTime::Format::Builder::import which was called: # once (6µs+1.48ms) by DateTime::Format::MySQL::BEGIN@11 at line 11 of DateTime/Format/MySQL.pm
sub import {
251400ns my $class = shift;
2616µs11.48ms $class->create_class( @_, class => (caller)[0] ) if @_;
# spent 1.48ms making 1 call to DateTime::Format::Builder::create_class
27}
28
29
# spent 1.48ms (55µs+1.42) within DateTime::Format::Builder::create_class which was called: # once (55µs+1.42ms) by DateTime::Format::Builder::import at line 26
sub create_class {
301300ns my $class = shift;
31133µs118µs my %args = validate(
# spent 18µs making 1 call to Params::Validate::XS::validate
32 @_,
33 {
34 class => { type => SCALAR, default => (caller)[0] },
35 version => { type => SCALAR, optional => 1 },
36 verbose => { type => SCALAR | GLOBREF | GLOB, optional => 1 },
37 parsers => { type => HASHREF },
38 groups => { type => HASHREF, optional => 1 },
39 constructor =>
40 { type => UNDEF | SCALAR | CODEREF, optional => 1 },
41 }
42 );
43
441400ns verbose( $args{verbose} ) if exists $args{verbose};
45
461500ns my $target = $args{class}; # where we're writing our methods and such.
47
48 # Create own lovely new package
49 {
503212µs223µs
# spent 15µs (6+8) within DateTime::Format::Builder::BEGIN@50 which was called: # once (6µs+8µs) by DateTime::Format::MySQL::BEGIN@11 at line 50
no strict 'refs';
# spent 15µs making 1 call to DateTime::Format::Builder::BEGIN@50 # spent 8µs making 1 call to strict::unimport
51
521300ns ${"${target}::VERSION"} = $args{version} if exists $args{version};
53
5413µs111µs $class->create_constructor(
# spent 11µs making 1 call to DateTime::Format::Builder::create_constructor
55 $target, exists $args{constructor},
56 $args{constructor}
57 );
58
59 # Turn groups of parser specs in to groups of parsers
60 {
612600ns my $specs = $args{groups};
621100ns my %groups;
63
6412µs for my $label ( keys %$specs ) {
65 my $parsers = $specs->{$label};
66 my $code = $class->create_parser($parsers);
67 $groups{$label} = $code;
68 }
69
7011µs $dispatch_data{$target} = \%groups;
71 }
72
73 # Write all our parser methods, creating parsers as we go.
7418µs while ( my ( $method, $parsers ) = each %{ $args{parsers} } ) {
7532µs my $globname = $target . "::$method";
76 croak "Will not override a preexisting method $method()"
7735µs if defined &{$globname};
78310µs31.39ms *$globname = $class->create_end_parser($parsers);
# spent 1.39ms making 3 calls to DateTime::Format::Builder::create_end_parser, avg 464µs/call
79 }
80 }
81
82}
83
84
# spent 11µs within DateTime::Format::Builder::create_constructor which was called: # once (11µs+0s) by DateTime::Format::Builder::create_class at line 54
sub create_constructor {
851300ns my $class = shift;
8611µs my ( $target, $intended, $value ) = @_;
87
881800ns my $new = $target . "::new";
891400ns $value = 1 unless $intended;
90
911200ns return unless $value;
9212µs return if not $intended and defined &$new;
931800ns croak "Will not override a preexisting constructor new()"
94 if defined &$new;
95
962531µs221µs
# spent 14µs (6+8) within DateTime::Format::Builder::BEGIN@96 which was called: # once (6µs+8µs) by DateTime::Format::MySQL::BEGIN@11 at line 96
no strict 'refs';
# spent 14µs making 1 call to DateTime::Format::Builder::BEGIN@96 # spent 8µs making 1 call to strict::unimport
97
981200ns return *$new = $value if ref $value eq 'CODE';
99 return *$new = sub {
100 my $class = shift;
101 croak "${class}->new takes no parameters." if @_;
102
103 my $self = bless {}, ref($class) || $class;
104
105 # If called on an object, clone, but we've nothing to
106 # clone
107
108 $self;
10917µs };
110}
111
112
# spent 1.37ms (20µs+1.35) within DateTime::Format::Builder::create_parser which was called 3 times, avg 456µs/call: # 3 times (20µs+1.35ms) by DateTime::Format::Builder::create_end_parser at line 132, avg 456µs/call
sub create_parser {
11331µs my $class = shift;
11432µs my @common = ( maker => $class );
11536µs if ( @_ == 1 ) {
1163500ns my $parsers = shift;
11735µs my @parsers = (
118 ( ref $parsers eq 'HASH' )
119 ? %$parsers
120 : ( ( ref $parsers eq 'ARRAY' ) ? @$parsers : $parsers )
121 );
12236µs31.35ms $parser->create_parser( \@common, @parsers );
# spent 1.35ms making 3 calls to DateTime::Format::Builder::Parser::create_parser, avg 450µs/call
123 }
124 else {
125 $parser->create_parser( \@common, @_ );
126 }
127}
128
129
130
# spent 1.39ms (15µs+1.38) within DateTime::Format::Builder::create_end_parser which was called 3 times, avg 464µs/call: # 3 times (15µs+1.38ms) by DateTime::Format::Builder::create_class at line 78, avg 464µs/call
sub create_end_parser {
1313800ns my ( $class, $parsers ) = @_;
132311µs61.38ms $class->create_method( $class->create_parser($parsers) );
# spent 1.37ms making 3 calls to DateTime::Format::Builder::create_parser, avg 456µs/call # spent 7µs making 3 calls to DateTime::Format::Builder::create_method, avg 2µs/call
133}
134
135
# spent 7µs within DateTime::Format::Builder::create_method which was called 3 times, avg 2µs/call: # 3 times (7µs+0s) by DateTime::Format::Builder::create_end_parser at line 132, avg 2µs/call
sub create_method {
13631µs my ( $class, $parser ) = @_;
137 return sub {
138 my $self = shift;
139 $parser->parse( $self, @_ );
140 }
14139µs}
142
143sub on_fail {
144 my ( $class, $input ) = @_;
145
146 my $pkg;
147 my $i = 0;
148 while ( ($pkg) = caller( $i++ ) ) {
149 last
150 if ( !UNIVERSAL::isa( $pkg, 'DateTime::Format::Builder' )
151 && !UNIVERSAL::isa( $pkg, 'DateTime::Format::Builder::Parser' ) );
152 }
153 local $Carp::CarpLevel = $i;
154 croak "Invalid date format: $input";
155}
156
157sub new {
158 my $class = shift;
159 croak "Constructor 'new' takes no parameters" if @_;
160 my $self = bless {
161 parser => sub { croak "No parser set." }
162 },
163 ref($class) || $class;
164 if ( ref $class ) {
165
166 # If called on an object, clone
167 $self->set_parser( $class->get_parser );
168
169 # and that's it. we don't store that much info per object
170 }
171 return $self;
172}
173
174sub parser {
175 my $class = shift;
176 my $parser = $class->create_end_parser( \@_ );
177
178 # Do we need to instantiate a new object for return,
179 # or are we modifying an existing object?
180 my $self;
181 $self = ref $class ? $class : $class->new();
182
183 $self->set_parser($parser);
184
185 $self;
186}
187
188sub clone {
189 my $self = shift;
190 croak "Calling object method as class method!" unless ref $self;
191 return $self->new();
192}
193
194sub set_parser {
195 my ( $self, $parser ) = @_;
196 croak "set_parser given something other than a coderef"
197 unless $parser
198 and ref $parser eq 'CODE';
199 $self->{parser} = $parser;
200 $self;
201}
202
203sub get_parser {
204 my ($self) = @_;
205 return $self->{parser};
206}
207
208sub parse_datetime {
209 my $self = shift;
210 croak "parse_datetime is an object method, not a class method."
211 unless ref $self and $self->isa(__PACKAGE__);
212 croak "No date specified." unless @_;
213 return $self->{parser}->( $self, @_ );
214}
215
216sub format_datetime {
217 croak __PACKAGE__ . "::format_datetime not implemented.";
218}
219
2201668µsrequire DateTime::Format::Builder::Parser;
221
22212µs1;
223
224# ABSTRACT: Create DateTime parser classes and objects.
225
226__END__