File Coverage

blib/lib/Rose/DB/Object/Metadata/Column/Datetime.pm
Criterion Covered Total %
statement 13 26 50.0
branch 0 12 0.0
condition 0 9 0.0
subroutine 5 8 62.5
pod 4 4 100.0
total 22 59 37.2


line stmt bran cond sub pod time code
1             package Rose::DB::Object::Metadata::Column::Datetime;
2              
3 1     1   6 use strict;
  1         2  
  1         33  
4              
5 1     1   6 use Rose::DB::Object::MakeMethods::Date;
  1         1  
  1         17  
6              
7 1     1   49 use Rose::DB::Object::Metadata::Column::Date;
  1         14  
  1         169  
8             our @ISA = qw(Rose::DB::Object::Metadata::Column::Date);
9              
10             our $VERSION = '0.788';
11              
12             __PACKAGE__->add_common_method_maker_argument_names
13             (
14             qw(time_zone)
15             );
16              
17             Rose::Object::MakeMethods::Generic->make_methods
18             (
19             { preserve_existing => 1 },
20             scalar => [ __PACKAGE__->common_method_maker_argument_names ]
21             );
22              
23             foreach my $type (__PACKAGE__->available_method_types)
24             {
25             __PACKAGE__->method_maker_type($type => 'datetime');
26             }
27              
28 2     2 1 10 sub type { 'datetime' }
29              
30             sub should_inline_value
31             {
32 0     0 1   my($self, $db, $value) = @_;
33 1     1   6 no warnings 'uninitialized';
  1         2  
  1         299  
34 0 0 0       return (($db->validate_datetime_keyword($value) && $db->should_inline_datetime_keyword($value)) ||
35             ($db->keyword_function_calls && $value =~ /^\w+\(.*\)$/)) ? 1 : 0;
36             }
37              
38             sub parse_value
39             {
40 0     0 1   my($self, $db) = (shift, shift);
41              
42 0           $self->parse_error(undef);
43              
44 0 0         my $dt = (defined $_[0]) ? $db->parse_datetime(@_) : undef;
45              
46 0 0         if($dt)
47             {
48 0 0 0       $dt->set_time_zone($self->time_zone || $db->server_time_zone)
49             if(UNIVERSAL::isa($dt, 'DateTime'));
50             }
51             else
52             {
53 0   0       $dt = Rose::DateTime::Util::parse_date($_[0], $self->time_zone || $db->server_time_zone);
54              
55 0 0         if(my $error = Rose::DateTime::Util->error)
56             {
57 0 0         $self->parse_error("Could not parse value '$_[0]' for column $self: $error")
58             if(defined $_[0]);
59             }
60             }
61              
62 0           return $dt;
63             }
64              
65 0     0 1   sub format_value { shift; shift->format_datetime(@_) }
  0            
66              
67             1;
68              
69             __END__
70              
71             =head1 NAME
72              
73             Rose::DB::Object::Metadata::Column::Datetime - Datetime column metadata.
74              
75             =head1 SYNOPSIS
76              
77             use Rose::DB::Object::Metadata::Column::Datetime;
78              
79             $col = Rose::DB::Object::Metadata::Column::Datetime->new(...);
80             $col->make_methods(...);
81             ...
82              
83             =head1 DESCRIPTION
84              
85             Objects of this class store and manipulate metadata for datetime columns in a database. Column metadata objects store information about columns (data type, size, etc.) and are responsible for creating object methods that manipulate column values.
86              
87             This class inherits from L<Rose::DB::Object::Metadata::Column::Date>. Inherited methods that are not overridden will not be documented a second time here. See the L<Rose::DB::Object::Metadata::Column::Date> documentation for more information.
88              
89             =head1 METHOD MAP
90              
91             =over 4
92              
93             =item C<get_set>
94              
95             L<Rose::DB::Object::MakeMethods::Date>, L<datetime|Rose::DB::Object::MakeMethods::Date/datetime>, C<type =E<gt> 'datetime', interface =E<gt> 'get_set', ...>
96              
97             =item C<get>
98              
99             L<Rose::DB::Object::MakeMethods::Date>, L<datetime|Rose::DB::Object::MakeMethods::Date/datetime>, C<type =E<gt> 'datetime', interface =E<gt> 'get', ...>
100              
101             =item C<set>
102              
103             L<Rose::DB::Object::MakeMethods::Date>, L<datetime|Rose::DB::Object::MakeMethods::Date/datetime>, C<type =E<gt> 'datetime', interface =E<gt> 'set', ...>
104              
105             =back
106              
107             See the L<Rose::DB::Object::Metadata::Column|Rose::DB::Object::Metadata::Column/"MAKING METHODS"> documentation for an explanation of this method map.
108              
109             =head1 OBJECT METHODS
110              
111             =over 4
112              
113             =item B<parse_value DB, VALUE>
114              
115             Convert VALUE to the equivalent L<DateTime> object. VALUE maybe returned unmodified if it is a valid datetime keyword or otherwise has special meaning to the underlying database. DB is a L<Rose::DB> object that is used as part of the parsing process. Both arguments are required.
116              
117             =item B<time_zone [TZ]>
118              
119             Get or set the time zone of the values stored in this column. TZ should be a time zone name that is understood by L<DateTime::TimeZone>.
120              
121             =item B<type>
122              
123             Returns "datetime".
124              
125             =back
126              
127             =head1 AUTHOR
128              
129             John C. Siracusa (siracusa@gmail.com)
130              
131             =head1 LICENSE
132              
133             Copyright (c) 2010 by John C. Siracusa. All rights reserved. This program is
134             free software; you can redistribute it and/or modify it under the same terms
135             as Perl itself.