NAME
Tie::Scalar::Timestamp - Create a scalar that always returns the current timestamp
SYNOPSIS
# create a timestamp variable that uses localtime
# and yyyy-mm-ddThh:mm:ss (ISO8601) format
tie my $timestamp, 'Tie::Scalar::Timestamp';
print "$timestamp\n"; # e.g. 2005-02-25T11:02:34
sleep 2; # wait 2 seconds...
print "$timestamp\n"; # ... 2005-02-25T11:02:36
# this will die; $timestamp is a readonly variable
$timestamp = '2004';
# create a timestamp variable that returns just the time in UTC
tie my $utc_timestamp, 'Tie::Scalar::Timestamp', { strftime => '%H:%M:%S', utc => 1 };
# set the default format
$Tie::Scalar::Timestamp::DEFAULT_STRFTIME = '%H:%M:%S';
DESCRIPTION
This is a very simple class that creates readonly scalars that always return the current timestamp. By default, it uses the format yyyy-mm-ddThh:mm:ss
(or, in strftime notation, %Y-%m-%dT%H:%M:%S
) and local time. You can optionally pass a hashref of options to the call to tie
to specify a pattern and whether to use UTC time instead of local time.
A variables tied to this class is readonly, and attempting to assign to it will raise an exception.
OPTIONS
The following options can be passed in a hashref to tie
.
strftime
-
The strftime pattern to fromat the timestamp as. The default pattern is
%Y-%m-%dT%H:%M:%S
. To change the default, set$Tie::Scalar::Timestamp::DEFAULT_STRFTIME
to your prefered pattern. utc
-
Use UTC time instead of local time.
no_die
-
Do not throw an exception when attempting to assign to a timestamp. This module will still emit a warning if you have warnings enabled.
SEE ALSO
perltie, Tie::Scalar, strftime(3)
AUTHOR
Peter Eichman, <peichman@cpan.org>
COPYRIGHT AND LICENSE
Copyright ©2005 by Peter Eichman.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.