Time::Piece::Adaptive - subclass of Time::Piece which allows the default


Time-Piece-Adaptive documentation  | view source Contained in the Time-Piece-Adaptive distribution.

Index


VERSION

Top

Version 0.03

NAME

Top

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

REQUIRES

Top

Subclasses Time::Piece.

SYNOPSIS

Top

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

Top

* gmtime
* localtime
* :override:

See Time::Piece for more.

METHODS

Top

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

Top

Time::Piece

AUTHOR

Top

Derek Price, <derek at ximbiot.com>

BUGS

Top

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

Top

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 & LICENSE

Top


Time-Piece-Adaptive documentation  | view source Contained in the Time-Piece-Adaptive distribution.