NAME
DateTime::LazyInit - DateTime objects with deferred validation DO NOT USE UNLESS YOU UNDERSTAND
SYNOPSIS
use DateTime::LazyInit;
my $dt = new DateTime::LazyInit( year=>2005, month=>7, day=>23 );
DESCRIPTION
LazyInit is designed to quickly create objects that have the potential to become DateTime objects. It does this by accepting anything you pass to it as being a valid parameter and value for a DateTime object.
Once a method is called that is beyond the simple set and get methods, the object will automatically inflate itself into a full DateTime object and then full validation will take place.
JUSTIFICATION
When working with a database or logs or many other data sources, it can be quite handy to have all the dates as DateTimes, however this can be slow as DateTime objects are large and need to do a lot of validation.
LazyInit defers that validation until it needs it.
WARNING
Because validation is deferred, this module assumes you will only ever give it valid data. If you try to give it anything else, it will happily accept it and then die once it needs to inflate into a DateTime object.
SIMPLE METHODS
As mentioned, this module supports simple constructor, set and get methods without inflating into a full DateTime object.
Construcor Methods
These methods replace their counterparts in DateTime. You need to pass options to them that match the parameters passed in DateTime. It should be obvious, but note that you cannot interchange them.
new
now
today
last_day_of_month
from_epoch
from_object
from_day_of_year
Set Methods
These methods simply set the parameter that will later be handed to datetime and care should be take to ensure that they are valid. For example, LazyInit will not complain if you set day
to 32
, but DateTime will fail once the object inflates.
year
month
day
hour
minute
second
nanosecond
time_zone
locale
Get Methods
These methods simply return the values set in the i<Set Methods> or a default value for any that aren't set. This default value is the same as DateTime's default value: month and day return 1, others return 0.
Note that there are no Get Methods for locale and time_zone. If you request either of these, the object will inflate.
year
month
day
hour
minute
second
nanosecond
DateTime::LazyInit
Methods
inflate( $method, @args )
This method forces the object to inflate. Note that this method cannot be called on the object once it has inflated as DateTime objects do not have an inflate method. If in doubt check the
ref()
of your object before callinginflate()
.
SEE ALSO
It is important to know DateTime before using LazyInit.
Any problems or queries should be directed to the mailing list: datetime@perl.org
For more information on the DateTime suite of modules, please see the website: http://datetime.perl.org/
AUTHOR
Rick Measham, <rickm@cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2005 by Rick Measham
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available.