Time::Piece::Adaptive - subclass of Time::Piece which allows the default stringification function to be set.
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.
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);
gmtime work like Time::Piece's versions, except they accept stringify arguments, as
$t->set_stringify ($format, $arg); print "The date is $t.";
$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
$format is a string, use it to format an output string using
$arg is ignored).
When called without specifying
$format, restore the default stringifier (
Like the Time::Piece functions of the same name, except
stringify_arg arguments are accepted.
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.";
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
<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.
You can find documentation for this module with the perldoc command.
You can also look for information at:
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.