NAME
Rose::DB::Object::MakeMethods::Time - Create time-related methods for Rose::DB::Object-derived objects.
SYNOPSIS
package MyDBObject;
our @ISA = qw(Rose::DB::Object);
use Rose::DB::Object::MakeMethods::Time
(
interval =>
[
't1' => { precision => 6 },
't2' => { default => '3 days 6 minutes 5 seconds' },
],
);
...
$o->t1('5 minutes 0.003 seconds');
$dt_dur = $o->t1; # DateTime::Duration object
print $o->t1->minutes; # 5
print $o->t1->nanoseconds; # 3000000
DESCRIPTION
Rose::DB::Object::MakeMethods::Time
creates methods that deal with times, and inherits from Rose::Object::MakeMethods. See the Rose::Object::MakeMethods documentation to learn about the interface. The method types provided by this module are described below.
All method types defined by this module are designed to work with objects that are subclasses of (or otherwise conform to the interface of) Rose::DB::Object. In particular, the object is expected to have a db method that returns a Rose::DB-derived object. See the Rose::DB::Object documentation for more details.
METHODS TYPES
- interval
-
Create get/set methods for interval (years, months, days, hours, minutes, seconds) attributes.
- Options
-
default
-
Determines the default value of the attribute.
hash_key
-
The key inside the hash-based object to use for the storage of this attribute. Defaults to the name of the method.
interface
-
Choose the interface. The default is
get_set
. precision
-
An integer number of places past the decimal point preserved for fractional seconds. Defaults to 0.
- Interfaces
-
get_set
-
Creates a get/set method for a interval (years, months, days, hours, minutes, seconds) attribute. When setting the attribute, the value is passed through the parse_interval method of the object's db attribute. If that fails, a fatal error will occur.
When saving to the database, the method will pass the attribute value through the format_interval method of the object's db attribute before returning it.
This method is designed to allow date values to make a round trip from and back into the database without ever being "inflated" into DateTime::Duration objects. Any use of the attribute (get or set) outside the context of loading from or saving to the database will cause the value to be "inflated" using the parse_interval method of the object's db attribute.
get
-
Creates an accessor method for a interval (years, months, days, hours, minutes, seconds) attribute. This method behaves like the
get_set
method, except that the value cannot be set. set
-
Creates a mutator method for a interval (years, months, days, hours, minutes, seconds) attribute. This method behaves like the
get_set
method, except that a fatal error will occur if no arguments are passed. It also does not support thetruncate
andformat
options.
Example:
package MyDBObject; our @ISA = qw(Rose::DB::Object); use Rose::DB::Object::MakeMethods::Time ( interval => [ 't1' => { precision => 6 }, 't2' => { default => '3 days 6 minutes 5 seconds' }, ], ); ... $o->t1('5 minutes 0.003 seconds'); $dt_dur = $o->t1; # DateTime::Duration object print $o->t1->minutes; # 5 print $o->t1->nanoseconds; # 3000000
AUTHOR
John C. Siracusa (siracusa@mindspring.com)
COPYRIGHT
Copyright (c) 2006 by John C. Siracusa. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.