NAME
Time::Duration::LocaleObject - time duration chosen by an object
SYNOPSIS
use Time::Duration::LocaleObject;
my $tdl = Time::Duration::LocaleObject->new;
print "next update: ", $tdl->duration(120) ,"\n";
DESCRIPTION
Time::Duration::LocaleObject
is an object-oriented wrapper around possible language-specific Time::Duration
modules. The methods correspond to the function calls in those modules. The target module is established from the user's locale, or can be set explicitly.
Most of the time this module is unnecessary, a single global choice based on the locale is enough, per Time::Duration::Locale
. But some OOPery is not too much more trouble than a plain functions module and it's handy if your program works with multiple locales more or less simultaneously (something pretty painful with the POSIX global-only things).
METHODS
In the following methods TDLObj means either a LocaleObject instance or the class name Time::Duration::Locale
.
print Time::Duration::LocaleObject->ago(120);
print $tdl->ago(120);
The class name form operates on a global singleton instance which is used by Time::Duration::Locale
.
Creation
Time::Duration::LocaleObject->new (key => value, ...)
-
Create and return a new LocaleObject. Optional key/value pairs can give an initial
module
orlanguage
as per the settings below, instead of using the locale settings.# for locale settings my $tdl = Time::Duration::LocaleObject->new; # for explicit language my $tdl = Time::Duration::LocaleObject->new (language => 'ja'); # for explicit language specified by module my $tdl = Time::Duration::LocaleObject->new (module => 'Time::Duration::la_PIG');
Duration Methods
As per the Time::Duration
functions. (Any new future functions should work too, methods pass through transparently.)
TDLObj->later ($seconds, [$precision])
TDLObj->later_exact ($seconds, [$precision])
TDLObj->earlier ($seconds, [$precision])
TDLObj->earlier_exact ($seconds, [$precision])
TDLObj->ago ($seconds, [$precision])
TDLObj->ago_exact ($seconds, [$precision])
TDLObj->from_now ($seconds, [$precision])
TDLObj->from_now_exact ($seconds, [$precision])
TDLObj->duration ($seconds, [$precision])
TDLObj->duration_exact ($seconds, [$precision])
TDLObj->concise ($str)
Settings Methods
$lang = TDLObj->language ()
TDLObj->language ($lang)
$module = TDLObj->module ()
TDLObj->module ($module)
-
Get or set the language to use, either in the form of a language code like "en" or "ja", or a module name like "Time::Duration" or "Time::Duration::ja".
A setting
undef
means no language has yet been selected. When setting the language the necessary module must exist and is loaded if not already loaded. TDLObj->setlocale ()
-
Set the language according to the user's locale settings such as the
LANGUAGE
andLANG
environment variables.This is called automatically by the duration methods above if no language has otherwise been set, so there's normally no need to explicitly
setlocale
. But call it if you change the environment variables and want TDLObj to follow.
OTHER NOTES
In the current implementation can()
checks whether the target module has such a function. This is probably what you want, though a later change of language could reveal extra funcs in another module. In any case a can()
subr of course follows the module of its target object when called, not whatever it saw when created.
A can()
subr returned is stored as a method in the Time::Duration::LocaleObject
symbol table, as a cache against future can()
calls and to bypass AUTOLOAD
if later invoked by name. Not sure if this is worth the trouble.
SEE ALSO
Time::Duration::Locale, Time::Duration, Time::Duration::ja Time::Duration::sv
HOME PAGE
http://user42.tuxfamily.org/time-duration-locale/index.html
COPYRIGHT
Copyright 2009, 2010 Kevin Ryde
Time-Duration-Locale is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Time-Duration-Locale is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Time-Duration-Locale. If not, see <http://www.gnu.org/licenses/>.