Filename | /usr/share/perl5/Date/Manip/Obj.pm |
Statements | Executed 252 statements in 3.52ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 8.86ms | 9.11ms | new_recur | Date::Manip::Obj::
1 | 1 | 1 | 4.93ms | 5.20ms | new_delta | Date::Manip::Obj::
1 | 1 | 1 | 3.11ms | 4.49ms | BEGIN@13 | Date::Manip::Obj::
9 | 7 | 2 | 179µs | 11.2ms | new (recurses: max depth 2, inclusive time 21.3ms) | Date::Manip::Obj::
1 | 1 | 1 | 12µs | 17µs | BEGIN@10 | Date::Manip::Obj::
1 | 1 | 1 | 11µs | 113µs | BEGIN@12 | Date::Manip::Obj::
1 | 1 | 1 | 11µs | 1.49ms | config | Date::Manip::Obj::
7 | 1 | 1 | 9µs | 9µs | _init_final | Date::Manip::Obj::
1 | 1 | 1 | 6µs | 23µs | new_date | Date::Manip::Obj::
1 | 1 | 1 | 6µs | 14µs | BEGIN@11 | Date::Manip::Obj::
1 | 1 | 1 | 4µs | 4µs | base | Date::Manip::Obj::
1 | 1 | 1 | 3µs | 3µs | END | Date::Manip::Obj::
1 | 1 | 1 | 2µs | 2µs | tz | Date::Manip::Obj::
0 | 0 | 0 | 0s | 0s | _init_args | Date::Manip::Obj::
0 | 0 | 0 | 0s | 0s | err | Date::Manip::Obj::
0 | 0 | 0 | 0s | 0s | get_config | Date::Manip::Obj::
0 | 0 | 0 | 0s | 0s | is_date | Date::Manip::Obj::
0 | 0 | 0 | 0s | 0s | is_delta | Date::Manip::Obj::
0 | 0 | 0 | 0s | 0s | is_recur | Date::Manip::Obj::
0 | 0 | 0 | 0s | 0s | new_config | Date::Manip::Obj::
0 | 0 | 0 | 0s | 0s | version | Date::Manip::Obj::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Date::Manip::Obj; | ||||
2 | # Copyright (c) 2008-2014 Sullivan Beck. All rights reserved. | ||||
3 | # This program is free software; you can redistribute it and/or modify it | ||||
4 | # under the same terms as Perl itself. | ||||
5 | |||||
6 | ######################################################################## | ||||
7 | ######################################################################## | ||||
8 | |||||
9 | 1 | 9µs | require 5.010000; | ||
10 | 2 | 21µs | 2 | 23µs | # spent 17µs (12+6) within Date::Manip::Obj::BEGIN@10 which was called:
# once (12µs+6µs) by Date::Manip::Date::BEGIN@14 at line 10 # spent 17µs making 1 call to Date::Manip::Obj::BEGIN@10
# spent 6µs making 1 call to warnings::import |
11 | 2 | 88µs | 2 | 22µs | # spent 14µs (6+8) within Date::Manip::Obj::BEGIN@11 which was called:
# once (6µs+8µs) by Date::Manip::Date::BEGIN@14 at line 11 # spent 14µs making 1 call to Date::Manip::Obj::BEGIN@11
# spent 8µs making 1 call to strict::import |
12 | 2 | 27µs | 2 | 215µs | # spent 113µs (11+102) within Date::Manip::Obj::BEGIN@12 which was called:
# once (11µs+102µs) by Date::Manip::Date::BEGIN@14 at line 12 # spent 113µs making 1 call to Date::Manip::Obj::BEGIN@12
# spent 102µs making 1 call to Exporter::import |
13 | 2 | 1.67ms | 2 | 4.53ms | # spent 4.49ms (3.11+1.38) within Date::Manip::Obj::BEGIN@13 which was called:
# once (3.11ms+1.38ms) by Date::Manip::Date::BEGIN@14 at line 13 # spent 4.49ms making 1 call to Date::Manip::Obj::BEGIN@13
# spent 42µs making 1 call to Exporter::import |
14 | |||||
15 | 1 | 100ns | our ($VERSION); | ||
16 | 1 | 300ns | $VERSION='6.47'; | ||
17 | 1 | 3µs | # spent 3µs within Date::Manip::Obj::END which was called:
# once (3µs+0s) by main::RUNTIME at line 131 of C4/Service.pm | ||
18 | |||||
19 | ######################################################################## | ||||
20 | # METHODS | ||||
21 | ######################################################################## | ||||
22 | |||||
23 | 1 | 2µs | my %classes = ( 'Date::Manip::Base' => 1, | ||
24 | 'Date::Manip::TZ' => 1, | ||||
25 | 'Date::Manip::Date' => 1, | ||||
26 | 'Date::Manip::Delta' => 1, | ||||
27 | 'Date::Manip::Recur' => 1, | ||||
28 | ); | ||||
29 | |||||
30 | # spent 11.2ms (179µs+11.0) within Date::Manip::Obj::new which was called 9 times, avg 1.25ms/call:
# 2 times (39µs+-39µs) by Date::Manip::Obj::new at line 153, avg 0s/call
# 2 times (29µs+-29µs) by Date::Manip::Obj::new at line 135, avg 0s/call
# once (32µs+6.47ms) by C4::Overdues::BEGIN@25 at line 64 of Date/Manip/DM6.pm
# once (16µs+4.59ms) by C4::Overdues::BEGIN@25 at line 67 of Date/Manip/DM6.pm
# once (24µs+29µs) by Date::Manip::Obj::new_recur at line 209
# once (24µs+9µs) by Date::Manip::Obj::new_delta at line 204
# once (13µs+5µs) by Date::Manip::Obj::new_date at line 199 | ||||
31 | 9 | 5µs | my(@args) = @_; | ||
32 | 9 | 4µs | my(@allargs) = @args; | ||
33 | |||||
34 | # $old is the object (if any) being used to create a new object | ||||
35 | # $new is the new object | ||||
36 | # $class is the class of the new object | ||||
37 | # $tz is a Date::Manip::TZ object to base the new object on | ||||
38 | # (only for Date, Delta, Recur objects) | ||||
39 | # $base is the Date::Manip::Base object to base the new object on | ||||
40 | # @opts options to pass to config method | ||||
41 | |||||
42 | 9 | 2µs | my($old,$new,$class,$tz,$base,@opts); | ||
43 | |||||
44 | # Get the class of the new object | ||||
45 | |||||
46 | 9 | 7µs | if (exists $classes{ $args[0] }) { | ||
47 | # $obj = new CLASS | ||||
48 | $class = shift(@args); | ||||
49 | |||||
50 | } elsif (ref($args[0])) { | ||||
51 | # $obj->new | ||||
52 | $class = ref($args[0]); | ||||
53 | |||||
54 | } else { | ||||
55 | warn "ERROR: [new] first argument must be a Date::Manip class/object\n"; | ||||
56 | return undef; | ||||
57 | } | ||||
58 | |||||
59 | # Get an old object | ||||
60 | |||||
61 | 9 | 4µs | if (ref($args[0])) { | ||
62 | # $old->new | ||||
63 | # new CLASS $old | ||||
64 | $old = shift(@args); | ||||
65 | } | ||||
66 | |||||
67 | # Find out if there are any config options (which will be the | ||||
68 | # final argument). | ||||
69 | |||||
70 | 9 | 2µs | if (@args && ref($args[$#args]) eq 'ARRAY') { | ||
71 | @opts = @{ pop(@args) }; | ||||
72 | } | ||||
73 | |||||
74 | # There must be at most 1 additional argument | ||||
75 | |||||
76 | 9 | 1µs | if (@args) { | ||
77 | if (@args > 1) { | ||||
78 | warn "ERROR: [new] unknown arguments\n"; | ||||
79 | return undef; | ||||
80 | } | ||||
81 | } | ||||
82 | |||||
83 | ######################## | ||||
84 | |||||
85 | # Get Base/TZ objects from an existing object | ||||
86 | |||||
87 | 9 | 2µs | if ($old) { | ||
88 | 3 | 5µs | if (ref($old) eq 'Date::Manip::Base') { | ||
89 | $base = $old; | ||||
90 | } elsif (ref($old) eq 'Date::Manip::TZ') { | ||||
91 | $tz = $old; | ||||
92 | $base = $$tz{'base'}; | ||||
93 | } elsif (ref($old) eq 'ARRAY') { | ||||
94 | my %old = @$old; | ||||
95 | $tz = $old{'tz'}; | ||||
96 | $base = $$tz{'base'}; | ||||
97 | } else { | ||||
98 | 3 | 2µs | $tz = $$old{'tz'}; | ||
99 | 3 | 2µs | $base = $$tz{'base'}; | ||
100 | } | ||||
101 | } | ||||
102 | |||||
103 | # Create a new empty object. | ||||
104 | |||||
105 | $new = { | ||||
106 | 9 | 10µs | 'data' => {}, | ||
107 | 'err' => '', | ||||
108 | }; | ||||
109 | |||||
110 | # Create Base/TZ objects if necessary | ||||
111 | |||||
112 | 9 | 2µs | if ($base && @opts) { | ||
113 | $base = dclone($base); | ||||
114 | $tz = new Date::Manip::TZ $base if ($tz); | ||||
115 | } | ||||
116 | |||||
117 | 9 | 2µs | my $init = 1; | ||
118 | 9 | 5µs | if ($class eq 'Date::Manip::Base') { | ||
119 | 2 | 600ns | if ($base) { | ||
120 | # new Date::Manip::Base $base | ||||
121 | if (@opts) { | ||||
122 | $new = $base; | ||||
123 | } else { | ||||
124 | # dclone doesn't handle regexps | ||||
125 | my $tmp = $$base{'data'}{'rx'}; | ||||
126 | delete $$base{'data'}{'rx'}; | ||||
127 | $new = dclone($base); | ||||
128 | $$base{'data'}{'rx'} = $tmp; | ||||
129 | $$new{'data'}{'rx'} = $tmp; | ||||
130 | } | ||||
131 | $init = 0; | ||||
132 | } | ||||
133 | |||||
134 | } elsif ($class eq 'Date::Manip::TZ') { | ||||
135 | 2 | 9µs | 2 | 0s | if ($tz) { # spent 10.3ms making 2 calls to Date::Manip::Obj::new, avg 5.15ms/call, recursion: max depth 2, sum of overlapping time 10.3ms |
136 | # new Date::Manip::TZ $tz | ||||
137 | if (@opts) { | ||||
138 | $new = $tz; | ||||
139 | } else { | ||||
140 | $new = dclone($tz); | ||||
141 | } | ||||
142 | $init = 0; | ||||
143 | } elsif (! $base) { | ||||
144 | $base = new Date::Manip::Base; | ||||
145 | } | ||||
146 | 2 | 1µs | $$new{'base'} = $base; | ||
147 | |||||
148 | } else { | ||||
149 | 5 | 2µs | if (! $tz) { | ||
150 | if ($base) { | ||||
151 | $tz = new Date::Manip::TZ $base; | ||||
152 | } else { | ||||
153 | 2 | 10µs | 2 | 0s | $tz = new Date::Manip::TZ; # spent 11.0ms making 2 calls to Date::Manip::Obj::new, avg 5.52ms/call, recursion: max depth 1, sum of overlapping time 11.0ms |
154 | } | ||||
155 | } | ||||
156 | 5 | 2µs | $$new{'tz'} = $tz; | ||
157 | } | ||||
158 | |||||
159 | 9 | 8µs | $$new{'args'} = [ @args ]; | ||
160 | 9 | 10µs | bless $new,$class; | ||
161 | |||||
162 | 9 | 17µs | 9 | 10.6ms | $new->_init() if ($init); # spent 10.3ms making 2 calls to Date::Manip::Base::_init, avg 5.13ms/call
# spent 286µs making 2 calls to Date::Manip::TZ::_init, avg 143µs/call
# spent 28µs making 1 call to Date::Manip::Recur::_init
# spent 22µs making 3 calls to Date::Manip::Date::_init, avg 7µs/call
# spent 7µs making 1 call to Date::Manip::Delta::_init |
163 | 9 | 2µs | $new->config(@opts) if (@opts); | ||
164 | 9 | 1µs | $new->_init_args() if (@args); | ||
165 | 9 | 20µs | 9 | 427µs | $new->_init_final(); # spent 418µs making 2 calls to Date::Manip::TZ::_init_final, avg 209µs/call
# spent 9µs making 7 calls to Date::Manip::Obj::_init_final, avg 1µs/call |
166 | 9 | 25µs | return $new; | ||
167 | } | ||||
168 | |||||
169 | sub _init_args { | ||||
170 | my($self) = @_; | ||||
171 | |||||
172 | my @args = @{ $$self{'args'} }; | ||||
173 | if (@args) { | ||||
174 | warn "WARNING: [new] invalid arguments: @args\n"; | ||||
175 | } | ||||
176 | } | ||||
177 | |||||
178 | # spent 9µs within Date::Manip::Obj::_init_final which was called 7 times, avg 1µs/call:
# 7 times (9µs+0s) by Date::Manip::Obj::new at line 165, avg 1µs/call | ||||
179 | 7 | 2µs | my($self) = @_; | ||
180 | 7 | 12µs | return; | ||
181 | } | ||||
182 | |||||
183 | sub new_config { | ||||
184 | my(@args) = @_; | ||||
185 | |||||
186 | # Make sure that @opts is passed in as the final argument. | ||||
187 | |||||
188 | if (! @args || | ||||
189 | ! (ref($args[$#args]) eq 'ARRAY')) { | ||||
190 | push(@args,['ignore','ignore']); | ||||
191 | } | ||||
192 | |||||
193 | return new(@args); | ||||
194 | } | ||||
195 | |||||
196 | # spent 23µs (6+18) within Date::Manip::Obj::new_date which was called:
# once (6µs+18µs) by C4::Overdues::BEGIN@25 at line 68 of Date/Manip/DM6.pm | ||||
197 | 1 | 800ns | my(@args) = @_; | ||
198 | 1 | 800ns | require Date::Manip::Date; | ||
199 | 1 | 4µs | 1 | 18µs | return new Date::Manip::Date @args; # spent 18µs making 1 call to Date::Manip::Obj::new |
200 | } | ||||
201 | # spent 5.20ms (4.93+270µs) within Date::Manip::Obj::new_delta which was called:
# once (4.93ms+270µs) by C4::Overdues::BEGIN@25 at line 69 of Date/Manip/DM6.pm | ||||
202 | 1 | 500ns | my(@args) = @_; | ||
203 | 1 | 756µs | require Date::Manip::Delta; | ||
204 | 1 | 8µs | 1 | 33µs | return new Date::Manip::Delta @args; # spent 33µs making 1 call to Date::Manip::Obj::new |
205 | } | ||||
206 | # spent 9.11ms (8.86+243µs) within Date::Manip::Obj::new_recur which was called:
# once (8.86ms+243µs) by C4::Overdues::BEGIN@25 at line 70 of Date/Manip/DM6.pm | ||||
207 | 1 | 800ns | my(@args) = @_; | ||
208 | 1 | 726µs | require Date::Manip::Recur; | ||
209 | 1 | 11µs | 1 | 53µs | return new Date::Manip::Recur @args; # spent 53µs making 1 call to Date::Manip::Obj::new |
210 | } | ||||
211 | |||||
212 | # spent 4µs within Date::Manip::Obj::base which was called:
# once (4µs+0s) by C4::Overdues::BEGIN@25 at line 71 of Date/Manip/DM6.pm | ||||
213 | 1 | 400ns | my($self) = @_; | ||
214 | 1 | 600ns | my $t = ref($self); | ||
215 | 1 | 800ns | if ($t eq 'Date::Manip::Base') { | ||
216 | return undef; | ||||
217 | } elsif ($t eq 'Date::Manip::TZ') { | ||||
218 | return $$self{'base'}; | ||||
219 | } else { | ||||
220 | 1 | 500ns | my $dmt = $$self{'tz'}; | ||
221 | 1 | 4µs | return $$dmt{'base'}; | ||
222 | } | ||||
223 | } | ||||
224 | |||||
225 | # spent 2µs within Date::Manip::Obj::tz which was called:
# once (2µs+0s) by C4::Overdues::BEGIN@25 at line 72 of Date/Manip/DM6.pm | ||||
226 | 1 | 300ns | my($self) = @_; | ||
227 | 1 | 500ns | my $t = ref($self); | ||
228 | |||||
229 | 1 | 500ns | if ($t eq 'Date::Manip::Base' || | ||
230 | $t eq 'Date::Manip::TZ') { | ||||
231 | return undef; | ||||
232 | } | ||||
233 | |||||
234 | 1 | 3µs | return $$self{'tz'}; | ||
235 | } | ||||
236 | |||||
237 | # spent 1.49ms (11µs+1.48) within Date::Manip::Obj::config which was called:
# once (11µs+1.48ms) by C4::Overdues::BEGIN@25 at line 65 of Date/Manip/DM6.pm | ||||
238 | 1 | 1µs | my($self,@opts) = @_; | ||
239 | 1 | 300ns | my $obj; | ||
240 | 1 | 1µs | if (ref($self) eq 'Date::Manip::Base' || | ||
241 | ref($self) eq 'Date::Manip::TZ') { | ||||
242 | $obj = $self; | ||||
243 | } else { | ||||
244 | 1 | 600ns | $obj = $$self{'tz'}; | ||
245 | } | ||||
246 | |||||
247 | 1 | 4µs | while (@opts) { | ||
248 | 1 | 500ns | my $var = shift(@opts); | ||
249 | 1 | 300ns | my $val = shift(@opts); | ||
250 | 1 | 4µs | 1 | 1.48ms | $obj->_config_var($var,$val); # spent 1.48ms making 1 call to Date::Manip::TZ_Base::_config_var |
251 | } | ||||
252 | } | ||||
253 | |||||
254 | sub get_config { | ||||
255 | my($self,@args) = @_; | ||||
256 | |||||
257 | my $base; | ||||
258 | my $t = ref($self); | ||||
259 | if ($t eq 'Date::Manip::Base') { | ||||
260 | $base = $self; | ||||
261 | } elsif ($t eq 'Date::Manip::TZ') { | ||||
262 | $base = $$self{'base'}; | ||||
263 | } else { | ||||
264 | my $dmt = $$self{'tz'}; | ||||
265 | $base = $$dmt{'base'}; | ||||
266 | } | ||||
267 | |||||
268 | if (@args) { | ||||
269 | my @ret; | ||||
270 | foreach my $var (@args) { | ||||
271 | if (exists $$base{'data'}{'sections'}{'conf'}{lc($var)}) { | ||||
272 | push @ret,$$base{'data'}{'sections'}{'conf'}{lc($var)}; | ||||
273 | } else { | ||||
274 | warn "ERROR: [config] invalid config variable: $var\n"; | ||||
275 | return ''; | ||||
276 | } | ||||
277 | } | ||||
278 | |||||
279 | if (@ret == 1) { | ||||
280 | return $ret[0]; | ||||
281 | } else { | ||||
282 | return @ret; | ||||
283 | } | ||||
284 | } | ||||
285 | |||||
286 | my @ret = sort keys %{ $$base{'data'}{'sections'}{'conf'} }; | ||||
287 | return @ret; | ||||
288 | } | ||||
289 | |||||
290 | sub err { | ||||
291 | my($self,$arg) = @_; | ||||
292 | if ($arg) { | ||||
293 | $$self{'err'} = ''; | ||||
294 | return; | ||||
295 | } else { | ||||
296 | return $$self{'err'}; | ||||
297 | } | ||||
298 | } | ||||
299 | |||||
300 | sub is_date { | ||||
301 | return 0; | ||||
302 | } | ||||
303 | sub is_delta { | ||||
304 | return 0; | ||||
305 | } | ||||
306 | sub is_recur { | ||||
307 | return 0; | ||||
308 | } | ||||
309 | |||||
310 | sub version { | ||||
311 | my($self,$flag) = @_; | ||||
312 | if ($flag && ref($self) ne 'Date::Manip::Base') { | ||||
313 | my $dmt; | ||||
314 | if (ref($self) eq 'Date::Manip::TZ') { | ||||
315 | $dmt = $self; | ||||
316 | } else { | ||||
317 | $dmt = $$self{'tz'}; | ||||
318 | } | ||||
319 | my $tz = $dmt->_now('systz'); | ||||
320 | return "$VERSION [$tz]"; | ||||
321 | } else { | ||||
322 | return $VERSION; | ||||
323 | } | ||||
324 | } | ||||
325 | |||||
326 | 1 | 3µs | 1; | ||
327 | # Local Variables: | ||||
328 | # mode: cperl | ||||
329 | # indent-tabs-mode: nil | ||||
330 | # cperl-indent-level: 3 | ||||
331 | # cperl-continued-statement-offset: 2 | ||||
332 | # cperl-continued-brace-offset: 0 | ||||
333 | # cperl-brace-offset: 0 | ||||
334 | # cperl-brace-imaginary-offset: 0 | ||||
335 | # cperl-label-offset: 0 | ||||
336 | # End: |