Version 0.03
Time::Piece::Adaptive - subclass of Time::Piece which allows the default stringification function to be set.
Subclasses Time::Piece.
See Time::Piece
I actually think this subclass encapsulates the behavior I would expect from Time::Piece, but I haven't been able to elicit a response from the authors of Time::Piece.
gmtime
localtime
:override:
See Time::Piece for more.
my $t1 = new Time::Piece::Adaptive (time, stringify => "%Y%m%d%H%M%S"); print "The MySql timestamp was $t1."; my $t2 = new Time::Piece::Adaptive (time, stringify => \&my_func, stringify_args => $my_data);
Like the constructor for Time::Piece, except it may set the default stringify function.
The above examples are semanticly equivalent to:
my $t1 = new Time::Piece::Adaptive (time); $t1->set_stringify ("%Y%m%d%H%M%S"); print "The MySql timestamp was $t1."; my $t2 = new Time::Piece::Adaptive (time); $t2->set_stringify (\&my_func, $my_data);
localtime and gmtime work like Time::Piece's versions, except they accept stringify arguments, as new.
new
$t->set_stringify ($format, $arg); print "The date is $t.";
If $format is a reference to a function, set the stringify function to $format, which should return a string when passed a reference to an instantiated Time::Piece and $arg.
$format
$arg
If $format is a string, use it to format an output string using strftime (any $arg is ignored).
strftime
When called without specifying $format, restore the default stringifier (&Time::Piece::cdate).
&Time::Piece::cdate
Like the Time::Piece functions of the same name, except stringify and stringify_arg arguments are accepted.
stringify
stringify_arg
Also, when a Time::Piece::Adaptive object is subtracted from an arbitrary object, it is converted to a string according to its stringify function and passed to perl for handling.
my $t = Time::Piece::Adaptive::strptime ($mysqltime, "%Y%m%d%H%M%S"); print "The MySql timestamp was $t."; my $t = Time::Piece::Adaptive::strptime ($mysqltime, "%Y%m%d%H%M%S", stringify => \&Time::Piece::Adaptive::cdate); print "The MySql timestamp was $t.";
Like the Time::Piece::strptime, except a stringify function may be set as per Time::Piece::Adaptive::new and, if the stringify function is not explicitly specified, then it is set by calling set_stringify ($format) on the new object with the same $format string passed to strptime.
Time::Piece::strptime
Time::Piece::Adaptive::new
set_stringify ($format)
strptime
Derek Price, <derek at ximbiot.com>
<derek at ximbiot.com>
Please report any bugs or feature requests to time-piece-adaptive at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Time-Piece-Adaptive. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
time-piece-adaptive at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Time::Piece::Adaptive
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Time-Piece-Adaptive
CPAN Ratings
http://cpanratings.perl.org/d/Time-Piece-Adaptive
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Time-Piece-Adaptive
Search CPAN
http://search.cpan.org/dist/Time-Piece-Adaptive
Copyright 2006 Derek Price, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Time::Piece::Adaptive, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Time::Piece::Adaptive
CPAN shell
perl -MCPAN -e shell install Time::Piece::Adaptive
For more information on module installation, please visit the detailed CPAN module installation guide.