Object/Metadata/Column/Time.pm untested

filter: Statementstmt 0.0% 0 / 72 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 162 CC 14 SCAR 24.5
CC
14
Cov
0%
precision
30.0
scale
20.0
init_with_dbi_column_info
12.0
CRAP 11.6
1 package Rose::DB::Object::Metadata::Column::Time;
2  
3 use strict;
4  
5 use Carp();
6  
7 use Rose::Object::MakeMethods::Generic;
8 use Rose::DB::Object::MakeMethods::Time;
9  
10 use Rose::DB::Object::Metadata::Column;
11 our @ISA = qw(Rose::DB::Object::Metadata::Column);
12  
13 our $VERSION = '0.788';
14  
15 __PACKAGE__->add_common_method_maker_argument_names('default', 'precision', 'scale');
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_class($type => 'Rose::DB::Object::MakeMethods::Time');
26 __PACKAGE__->method_maker_type($type => 'time');
27 }
28  
29 sub type { 'time' }
30  
31 sub init_with_dbi_column_info
32 {
33 my($self, $col_info) = @_;
34  
35 $self->SUPER::init_with_dbi_column_info($col_info);
36  
37 $self->scale($col_info->{'TIME_SCALE'})
38 if(defined $col_info->{'TIME_SCALE'});
39  
40 $self->precision($col_info->{'TIME_PRECISION'})
41 if(defined $col_info->{'TIME_PRECISION'});
42  
43 return;
44 }
45  
46 sub should_inline_value
47 {
48 my($self, $db, $value) = @_;
49 no warnings 'uninitialized';
50 return (($db->validate_time_keyword($value) && $db->should_inline_time_keyword($value)) ||
51 ($db->keyword_function_calls && $value =~ /^\w+\(.*\)$/)) ? 1 : 0;
52 }
53  
54 sub method_should_set
55 {
56 my($self, $type, $args) = @_;
57  
58 return 1 if($type eq 'set' || $type eq 'get_set');
59 return 0 if($type eq 'get');
60  
61 return $self->SUPER::method_should_set($type, $args);
62 }
63  
64 sub parse_value { shift; shift->parse_time(@_) }
65 sub format_value { shift; shift->format_time(@_) }
66  
67 sub method_uses_formatted_key
68 {
69 my($self, $type) = @_;
70 return 1 if($type eq 'get' || $type eq 'set' || $type eq 'get_set');
71 return 0;
72 }
73  
74 use constant DEFAULT_PRECISION => 6; # HHMMSS
75 use constant DEFAULT_SCALE => 0; # HHMMSS (no fractional seconds)
76  
77 sub precision
78 {
79 my($self) = shift;
80  
81 if(@_)
82 {
83 my $p = shift;
84  
85 unless($p == 2 || $p == 4 || $p >= 6)
86 {
87 Carp::croak "Invalid precision: $p. Time column precision must be 2, 4, or >= 6";
88 }
89  
90 $self->{'precision'} = $p;
91 $self->{'scale'} = $self->{'precision'} - DEFAULT_PRECISION;
92 $self->{'scale'} = 0 if($self->{'scale'} < 0);
93 return $self->{'precision'};
94 }
95  
96 return $self->{'precision'} if(defined $self->{'precision'});
97 return $self->{'precision'} = DEFAULT_PRECISION;
98 }
99  
100 sub scale
101 {
102 my($self) = shift;
103  
104 if(@_)
105 {
106 $self->{'scale'} = defined $_[0] ? $_[0] : 0;
107 $self->{'precision'} = DEFAULT_PRECISION + $self->{'scale'};
108 return $self->{'scale'};
109 }
110  
111 return $self->{'scale'} if(defined $self->{'scale'});
112 return $self->{'scale'} = DEFAULT_PRECISION;
113 }
114  
115 1;
116  
117 __END__