Filename | /usr/share/perl5/DateTime/Format/Builder.pm |
Statements | Executed 91 statements in 1.89ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 114µs | 3.98ms | create_class | DateTime::Format::Builder::
3 | 1 | 1 | 89µs | 3.78ms | create_end_parser | DateTime::Format::Builder::
1 | 1 | 1 | 40µs | 162µs | BEGIN@12 | DateTime::Format::Builder::
3 | 1 | 1 | 39µs | 3.67ms | create_parser | DateTime::Format::Builder::
1 | 1 | 1 | 35µs | 35µs | BEGIN@11 | DateTime::Format::Builder::
1 | 1 | 1 | 22µs | 27µs | BEGIN@10 | DateTime::Format::Builder::
1 | 1 | 1 | 19µs | 19µs | create_constructor | DateTime::Format::Builder::
1 | 1 | 1 | 19µs | 39µs | BEGIN@13 | DateTime::Format::Builder::
3 | 1 | 1 | 18µs | 18µs | create_method | DateTime::Format::Builder::
1 | 1 | 1 | 17µs | 135µs | BEGIN@14 | DateTime::Format::Builder::
1 | 1 | 1 | 13µs | 3.99ms | import | DateTime::Format::Builder::
1 | 1 | 1 | 12µs | 29µs | BEGIN@122 | DateTime::Format::Builder::
1 | 1 | 1 | 11µs | 36µs | BEGIN@76 | DateTime::Format::Builder::
1 | 1 | 1 | 10µs | 46µs | BEGIN@17 | DateTime::Format::Builder::
0 | 0 | 0 | 0s | 0s | __ANON__[:134] | DateTime::Format::Builder::
0 | 0 | 0 | 0s | 0s | __ANON__[:190] | DateTime::Format::Builder::
0 | 0 | 0 | 0s | 0s | __ANON__[:230] | DateTime::Format::Builder::
0 | 0 | 0 | 0s | 0s | clone | DateTime::Format::Builder::
0 | 0 | 0 | 0s | 0s | format_datetime | DateTime::Format::Builder::
0 | 0 | 0 | 0s | 0s | get_parser | DateTime::Format::Builder::
0 | 0 | 0 | 0s | 0s | new | DateTime::Format::Builder::
0 | 0 | 0 | 0s | 0s | on_fail | DateTime::Format::Builder::
0 | 0 | 0 | 0s | 0s | parse_datetime | DateTime::Format::Builder::
0 | 0 | 0 | 0s | 0s | parser | DateTime::Format::Builder::
0 | 0 | 0 | 0s | 0s | set_parser | DateTime::Format::Builder::
0 | 0 | 0 | 0s | 0s | verbose | DateTime::Format::Builder::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package DateTime::Format::Builder; | ||||
2 | # $Id: Builder.pm 3748 2007-09-01 20:56:42Z autarch $ | ||||
3 | |||||
4 | =begin comments | ||||
5 | |||||
- - | |||||
10 | 3 | 32µs | 2 | 31µs | # spent 27µs (22+4) within DateTime::Format::Builder::BEGIN@10 which was called:
# once (22µs+4µs) by DateTime::Format::MySQL::BEGIN@11 at line 10 # spent 27µs making 1 call to DateTime::Format::Builder::BEGIN@10
# spent 4µs making 1 call to strict::import |
11 | 3 | 55µs | 1 | 35µs | # spent 35µs within DateTime::Format::Builder::BEGIN@11 which was called:
# once (35µs+0s) by DateTime::Format::MySQL::BEGIN@11 at line 11 # spent 35µs making 1 call to DateTime::Format::Builder::BEGIN@11 |
12 | 3 | 66µs | 2 | 284µs | # spent 162µs (40+122) within DateTime::Format::Builder::BEGIN@12 which was called:
# once (40µs+122µs) by DateTime::Format::MySQL::BEGIN@11 at line 12 # spent 162µs making 1 call to DateTime::Format::Builder::BEGIN@12
# spent 122µs making 1 call to Exporter::import |
13 | 3 | 69µs | 3 | 58µs | # spent 39µs (19+20) within DateTime::Format::Builder::BEGIN@13 which was called:
# once (19µs+20µs) by DateTime::Format::MySQL::BEGIN@11 at line 13 # spent 39µs making 1 call to DateTime::Format::Builder::BEGIN@13
# spent 17µs making 1 call to UNIVERSAL::VERSION
# spent 2µs making 1 call to UNIVERSAL::import |
14 | 1 | 12µs | 1 | 118µs | # spent 135µs (17+118) within DateTime::Format::Builder::BEGIN@14 which was called:
# once (17µs+118µs) by DateTime::Format::MySQL::BEGIN@11 at line 16 # spent 118µs making 1 call to Exporter::import |
15 | validate SCALAR ARRAYREF HASHREF SCALARREF CODEREF GLOB GLOBREF UNDEF | ||||
16 | 2 | 30µs | 1 | 135µs | ); # spent 135µs making 1 call to DateTime::Format::Builder::BEGIN@14 |
17 | 3 | 200µs | 2 | 82µs | # spent 46µs (10+36) within DateTime::Format::Builder::BEGIN@17 which was called:
# once (10µs+36µs) by DateTime::Format::MySQL::BEGIN@11 at line 17 # spent 46µs making 1 call to DateTime::Format::Builder::BEGIN@17
# spent 36µs making 1 call to vars::import |
18 | |||||
19 | 1 | 1µs | my $parser = 'DateTime::Format::Builder::Parser'; | ||
20 | 1 | 600ns | $VERSION = '0.7901'; | ||
21 | |||||
22 | # Developer oriented methods | ||||
23 | |||||
24 | =pod | ||||
25 | |||||
- - | |||||
30 | sub verbose | ||||
31 | { | ||||
32 | warn "Use of verbose() deprecated for the interim."; | ||||
33 | 1; | ||||
34 | } | ||||
35 | |||||
36 | =pod | ||||
37 | |||||
- - | |||||
45 | sub import | ||||
46 | # spent 3.99ms (13µs+3.98) within DateTime::Format::Builder::import which was called:
# once (13µs+3.98ms) by DateTime::Format::MySQL::BEGIN@11 at line 11 of DateTime/Format/MySQL.pm | ||||
47 | 1 | 2µs | my $class = shift; | ||
48 | 1 | 10µs | 1 | 3.98ms | $class->create_class( @_, class => (caller)[0] ) if @_; # spent 3.98ms making 1 call to DateTime::Format::Builder::create_class |
49 | } | ||||
50 | |||||
51 | =pod | ||||
52 | |||||
- - | |||||
58 | sub create_class | ||||
59 | # spent 3.98ms (114µs+3.86) within DateTime::Format::Builder::create_class which was called:
# once (114µs+3.86ms) by DateTime::Format::Builder::import at line 48 | ||||
60 | 1 | 1µs | my $class = shift; | ||
61 | 1 | 92µs | 1 | 67µs | my %args = validate( @_, { # spent 67µs making 1 call to Params::Validate::_validate # spent 4µs executing statements in string eval |
62 | class => { type => SCALAR, default => (caller)[0] }, | ||||
63 | version => { type => SCALAR, optional => 1 }, | ||||
64 | verbose => { type => SCALAR|GLOBREF|GLOB, optional => 1 }, | ||||
65 | parsers => { type => HASHREF }, | ||||
66 | groups => { type => HASHREF, optional => 1 }, | ||||
67 | constructor => { type => UNDEF|SCALAR|CODEREF, optional => 1 }, | ||||
68 | }); | ||||
69 | |||||
70 | 1 | 900ns | verbose( $args{verbose} ) if exists $args{verbose}; | ||
71 | |||||
72 | 1 | 1µs | my $target = $args{class}; # where we're writing our methods and such. | ||
73 | |||||
74 | # Create own lovely new package | ||||
75 | { | ||||
76 | 4 | 261µs | 2 | 61µs | # spent 36µs (11+25) within DateTime::Format::Builder::BEGIN@76 which was called:
# once (11µs+25µs) by DateTime::Format::MySQL::BEGIN@11 at line 76 # spent 36µs making 1 call to DateTime::Format::Builder::BEGIN@76
# spent 25µs making 1 call to strict::unimport |
77 | |||||
78 | |||||
79 | 1 | 700ns | ${"${target}::VERSION"} = $args{version} if exists $args{version}; | ||
80 | |||||
81 | 1 | 6µs | 1 | 19µs | $class->create_constructor( # spent 19µs making 1 call to DateTime::Format::Builder::create_constructor |
82 | $target, exists $args{constructor}, $args{constructor} ); | ||||
83 | |||||
84 | # Turn groups of parser specs in to groups of parsers | ||||
85 | { | ||||
86 | 2 | 1µs | my $specs = $args{groups}; | ||
87 | 1 | 400ns | my %groups; | ||
88 | |||||
89 | 1 | 3µs | for my $label ( keys %$specs ) | ||
90 | { | ||||
91 | my $parsers = $specs->{$label}; | ||||
92 | my $code = $class->create_parser( $parsers ); | ||||
93 | $groups{$label} = $code; | ||||
94 | } | ||||
95 | |||||
96 | 1 | 3µs | $dispatch_data{$target} = \%groups; | ||
97 | } | ||||
98 | |||||
99 | # Write all our parser methods, creating parsers as we go. | ||||
100 | 1 | 19µs | while (my ($method, $parsers) = each %{ $args{parsers} }) | ||
101 | { | ||||
102 | 3 | 5µs | my $globname = $target."::$method"; | ||
103 | 3 | 6µs | croak "Will not override a preexisting method $method()" if defined &{$globname}; | ||
104 | 3 | 84µs | 3 | 3.78ms | *$globname = $class->create_end_parser( $parsers ); # spent 3.78ms making 3 calls to DateTime::Format::Builder::create_end_parser, avg 1.26ms/call |
105 | } | ||||
106 | } | ||||
107 | |||||
108 | } | ||||
109 | |||||
110 | sub create_constructor | ||||
111 | # spent 19µs within DateTime::Format::Builder::create_constructor which was called:
# once (19µs+0s) by DateTime::Format::Builder::create_class at line 81 | ||||
112 | 1 | 2µs | my $class = shift; | ||
113 | 1 | 2µs | my ( $target, $intended, $value ) = @_; | ||
114 | |||||
115 | 1 | 2µs | my $new = $target."::new"; | ||
116 | 1 | 500ns | $value = 1 unless $intended; | ||
117 | |||||
118 | 1 | 200ns | return unless $value; | ||
119 | 1 | 2µs | return if not $intended and defined &$new; | ||
120 | 1 | 800ns | croak "Will not override a preexisting constructor new()" if defined &$new; | ||
121 | |||||
122 | 3 | 714µs | 2 | 45µs | # spent 29µs (12+16) within DateTime::Format::Builder::BEGIN@122 which was called:
# once (12µs+16µs) by DateTime::Format::MySQL::BEGIN@11 at line 122 # spent 29µs making 1 call to DateTime::Format::Builder::BEGIN@122
# spent 16µs making 1 call to strict::unimport |
123 | |||||
124 | 1 | 1µs | return *$new = $value if ref $value eq 'CODE'; | ||
125 | return *$new = sub { | ||||
126 | my $class = shift; | ||||
127 | croak "${class}->new takes no parameters." if @_; | ||||
128 | |||||
129 | my $self = bless {}, ref($class)||$class; | ||||
130 | # If called on an object, clone, but we've nothing to | ||||
131 | # clone | ||||
132 | |||||
133 | $self; | ||||
134 | 1 | 12µs | }; | ||
135 | } | ||||
136 | |||||
137 | =pod | ||||
138 | |||||
- - | |||||
145 | sub create_parser | ||||
146 | # spent 3.67ms (39µs+3.63) within DateTime::Format::Builder::create_parser which was called 3 times, avg 1.22ms/call:
# 3 times (39µs+3.63ms) by DateTime::Format::Builder::create_end_parser at line 174, avg 1.22ms/call | ||||
147 | 3 | 3µs | my $class = shift; | ||
148 | 3 | 4µs | my @common = ( maker => $class ); | ||
149 | 3 | 13µs | if (@_ == 1) | ||
150 | { | ||||
151 | 3 | 1µs | my $parsers = shift; | ||
152 | 3 | 9µs | my @parsers = ( | ||
153 | (ref $parsers eq 'HASH' ) ? %$parsers : | ||||
154 | ( ( ref $parsers eq 'ARRAY' ) ? @$parsers : $parsers) | ||||
155 | ); | ||||
156 | 3 | 12µs | 3 | 3.63ms | $parser->create_parser( \@common, @parsers ); # spent 3.63ms making 3 calls to DateTime::Format::Builder::Parser::create_parser, avg 1.21ms/call |
157 | } | ||||
158 | else | ||||
159 | { | ||||
160 | $parser->create_parser( \@common, @_ ); | ||||
161 | } | ||||
162 | } | ||||
163 | |||||
164 | =pod | ||||
165 | |||||
- - | |||||
171 | sub create_end_parser | ||||
172 | # spent 3.78ms (89µs+3.69) within DateTime::Format::Builder::create_end_parser which was called 3 times, avg 1.26ms/call:
# 3 times (89µs+3.69ms) by DateTime::Format::Builder::create_class at line 104, avg 1.26ms/call | ||||
173 | 3 | 4µs | my ($class, $parsers) = @_; | ||
174 | 3 | 24µs | 6 | 3.69ms | $class->create_method( $class->create_parser( $parsers ) ); # spent 3.67ms making 3 calls to DateTime::Format::Builder::create_parser, avg 1.22ms/call
# spent 18µs making 3 calls to DateTime::Format::Builder::create_method, avg 6µs/call |
175 | } | ||||
176 | |||||
177 | =pod | ||||
178 | |||||
- - | |||||
184 | sub create_method | ||||
185 | # spent 18µs within DateTime::Format::Builder::create_method which was called 3 times, avg 6µs/call:
# 3 times (18µs+0s) by DateTime::Format::Builder::create_end_parser at line 174, avg 6µs/call | ||||
186 | 3 | 3µs | my ($class, $parser) = @_; | ||
187 | return sub { | ||||
188 | my $self = shift; | ||||
189 | $parser->parse( $self, @_); | ||||
190 | } | ||||
191 | 3 | 19µs | } | ||
192 | |||||
193 | =pod | ||||
194 | |||||
- - | |||||
200 | sub on_fail | ||||
201 | { | ||||
202 | my ($class, $input) = @_; | ||||
203 | |||||
204 | my $pkg; | ||||
205 | my $i = 0; | ||||
206 | while (($pkg) = caller($i++)) { | ||||
207 | last if (!UNIVERSAL::isa($pkg, 'DateTime::Format::Builder') && | ||||
208 | !UNIVERSAL::isa($pkg, 'DateTime::Format::Builder::Parser')); | ||||
209 | } | ||||
210 | local $Carp::CarpLevel = $i; | ||||
211 | croak "Invalid date format: $input"; | ||||
212 | } | ||||
213 | |||||
214 | # | ||||
215 | # User oriented methods | ||||
216 | # | ||||
217 | |||||
218 | =pod | ||||
219 | |||||
- - | |||||
225 | sub new | ||||
226 | { | ||||
227 | my $class = shift; | ||||
228 | croak "Constructor 'new' takes no parameters" if @_; | ||||
229 | my $self = bless { | ||||
230 | parser => sub { croak "No parser set." } | ||||
231 | }, ref($class)||$class; | ||||
232 | if (ref $class) | ||||
233 | { | ||||
234 | # If called on an object, clone | ||||
235 | $self->set_parser( $class->get_parser ); | ||||
236 | # and that's it. we don't store that much info per object | ||||
237 | } | ||||
238 | return $self; | ||||
239 | } | ||||
240 | |||||
241 | sub parser | ||||
242 | { | ||||
243 | my $class = shift; | ||||
244 | my $parser = $class->create_end_parser( \@_ ); | ||||
245 | |||||
246 | # Do we need to instantiate a new object for return, | ||||
247 | # or are we modifying an existing object? | ||||
248 | my $self; | ||||
249 | $self = ref $class ? $class : $class->new(); | ||||
250 | |||||
251 | $self->set_parser( $parser ); | ||||
252 | |||||
253 | $self; | ||||
254 | } | ||||
255 | |||||
256 | sub clone | ||||
257 | { | ||||
258 | my $self = shift; | ||||
259 | croak "Calling object method as class method!" unless ref $self; | ||||
260 | return $self->new(); | ||||
261 | } | ||||
262 | |||||
263 | sub set_parser | ||||
264 | { | ||||
265 | my ($self, $parser) = @_; | ||||
266 | croak "set_parser given something other than a coderef" unless $parser | ||||
267 | and ref $parser eq 'CODE'; | ||||
268 | $self->{parser} = $parser; | ||||
269 | $self; | ||||
270 | } | ||||
271 | |||||
272 | sub get_parser | ||||
273 | { | ||||
274 | my ($self) = @_; | ||||
275 | return $self->{parser}; | ||||
276 | } | ||||
277 | |||||
278 | sub parse_datetime | ||||
279 | { | ||||
280 | my $self = shift; | ||||
281 | croak "parse_datetime is an object method, not a class method." | ||||
282 | unless ref $self and $self->isa( __PACKAGE__ ); | ||||
283 | croak "No date specified." unless @_; | ||||
284 | return $self->{parser}->( $self, @_ ); | ||||
285 | } | ||||
286 | |||||
287 | sub format_datetime | ||||
288 | { | ||||
289 | croak __PACKAGE__."::format_datetime not implemented."; | ||||
290 | } | ||||
291 | |||||
292 | 1 | 92µs | require DateTime::Format::Builder::Parser; | ||
293 | |||||
294 | |||||
295 | =pod | ||||
296 | |||||
- - | |||||
301 | 1 | 10µs | 1; |