Derek Price > Time-Piece-Adaptive-0.03 > Time::Piece::Adaptive

Download:
Time-Piece-Adaptive-0.03.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.03   Source  

VERSION ^

Version 0.03

NAME ^

Time::Piece::Adaptive - subclass of Time::Piece which allows the default stringification function to be set.

REQUIRES ^

Subclasses Time::Piece.

SYNOPSIS ^

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.

EXPORT ^

See Time::Piece for more.

METHODS ^

new

  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

gmtime

localtime and gmtime work like Time::Piece's versions, except they accept stringify arguments, as new.

set_stringify

  $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.

If $format is a string, use it to format an output string using strftime (any $arg is ignored).

When called without specifying $format, restore the default stringifier (&Time::Piece::cdate).

add

subtract

Like the Time::Piece functions of the same name, except stringify and 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.

strptime

  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.

SEE ALSO ^

Time::Piece

AUTHOR ^

Derek Price, <derek at ximbiot.com>

BUGS ^

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.

SUPPORT ^

You can find documentation for this module with the perldoc command.

    perldoc Time::Piece::Adaptive

You can also look for information at:

COPYRIGHT & LICENSE ^

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.

syntax highlighting: