blib/lib/DBIx/Class/InflateColumn/DateTime/WithTimeZone.pm

filter: Statementstmt 98.0% 50 / 51 Branchbran 86.3% 19 / 22 Conditioncond 72.7% 8 / 11 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 88.0% 88 / 100 CC 16 SCAR 17.7
CC
16
Cov
92%
register_column
10.1
_post_inflate_datetime
4.0
_pre_deflate_datetime
3.0
CRAP 5.8
↑ Summary
1 package DBIx::Class::InflateColumn::DateTime::WithTimeZone;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use base 'DBIx::Class::InflateColumn::DateTime';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 our $VERSION = '0.03';
8  
9 6 ▶use DateTime::TimeZone;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 19 ▶sub register_column {
Subroutine register_column: called CC=10 SCAR=23.2
Pod documented
12 19 my ( $self, $column, $info, @rest ) = @_;
13  
14 19 my $msg = "Column $column:";
15  
16 # NOTE: must update $info before calling parent, b/c parent copies $info
17 19 ▶ if ( my $tz_source = $info->{timezone_source} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tz_source = $info->{"timezone_source"}) 9 10 19
18  
19 # force InflateColumn::DateTime to convert to UTC before storing
20 9 ▶ $info->{timezone} ||= 'UTC';
Condition100%2/2
$info->{"timezone"} ||= "UTC"
l!l
36
MC/DC100%1/1
$info->{"timezone"} ||= "UTC"
$info->{"timezone"}
Truth table100%2/2
A
A= $info->{"timezone"}
Aresult
11
00
21 9 ▶ if ( $info->{timezone} ne 'UTC' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{"timezone"} ne "UTC") 1 8 9
22 1 $self->throw_exception( "$msg saving non-UTC datetimes in database is not supported" );
23 }
24 }
25  
26 18 $self->next::method( $column, $info, @rest );
27  
28 18 ▶ if ( my $tz_source = $info->{timezone_source} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tz_source = $info->{"timezone_source"}) 8 10 18
29 8 my $ic_dt_method = $info->{_ic_dt_method};
30 8 ▶ if ( !$ic_dt_method || !$ic_dt_method =~ /(?: datetime | timestamp )/x ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ic_dt_method or !$ic_dt_method =~ /(?: datetime | timestamp )/x) 1 7 8
Condition66%2/3
not $ic_dt_method or !$ic_dt_method =~ /(?: datetime | timestamp )/x
l!l&&r!l&&!r
107
MC/DC50%1/2
not $ic_dt_method or !$ic_dt_method =~ /(?: datetime | timestamp )/x
not $ic_dt_method !$ic_dt_method =~ /(?: datetime | timestamp )/x
Truth table66%2/3
not(A) or not(B)
A= not $ic_dt_methodB= !$ic_dt_method =~ /(?: datetime | timestamp )/x
ABresult
1X1
011
000
31 1 $self->throw_exception( "$msg timezone_source requires datetime data_type");
32 }
33  
34 7 ▶ if ( !$self->has_column($tz_source) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has_column($tz_source)) 1 6 7
35 1 $self->throw_exception( "$msg could not find column $tz_source for timezone_source" );
36 }
37  
38 6 my $tz_info = $self->column_info($tz_source);
39  
40 6 ▶ if ( $info->{is_nullable} && !$tz_info->{is_nullable} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{"is_nullable"} and not $tz_info->{"is_nullable"}) 0 6 6
Condition66%2/3
$info->{"is_nullable"} and not $tz_info->{"is_nullable"}
!ll&&!rl&&r
420
MC/DC0%0/2
$info->{"is_nullable"} and not $tz_info->{"is_nullable"}
$info->{"is_nullable"} not $tz_info->{"is_nullable"}
Truth table66%2/3
A and not(B)
A= $info->{"is_nullable"}B= not $tz_info->{"is_nullable"}
ABresult
0X0
100
111
41 0 $self->throw_exception( "$msg: is nullable, so $tz_source must also be nullable" );
42 }
43 }
44 }
45  
46 6 my %tz_cache;
47  
48 2 ▶sub _get_cached_tz {
Subroutine _get_cached_tz: called CC=2 SCAR=7.1
49 2 my ( $self, $tz ) = @_;
50 2 ▶ return $tz_cache{$tz} ||= DateTime::TimeZone->new( name => $tz );
Condition66%2/3
$tz_cache{$tz} ||= "DateTime::TimeZone"->new("name", $tz)
l!l&&r!l&&!r
110
MC/DC0%0/2
$tz_cache{$tz} ||= "DateTime::TimeZone"->new("name", $tz)
$tz_cache{$tz} "DateTime::TimeZone"->new("name", $tz)
Truth table66%2/3
A ||= B
A= $tz_cache{$tz}B= "DateTime::TimeZone"->new("name", $tz)
ABresult
1X1
011
000
51 }
52  
53 4 ▶sub _post_inflate_datetime {
Subroutine _post_inflate_datetime: called CC=4 SCAR=13.9
54 4 my ( $self, $dt, $info ) = @_;
55  
56 4 $dt = $self->next::method( $dt, $info );
57  
58 4 ▶ if ( my $tz_src = $info->{timezone_source} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tz_src = $info->{"timezone_source"}) 4 0 4
59 4 ▶ if ( !$self->has_column_loaded($tz_src) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has_column_loaded($tz_src)) 1 3 4
60 1 my $colname = $info->{__dbic_colname};
61 1 $self->throw_exception(
62 "$colname needs time zone from $tz_src, but $tz_src is not loaded: check query?" );
63 }
64 3 my $tz = $self->get_column($tz_src);
65 3 ▶ if ($tz) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tz) { } 2 1 3
66 2 $dt->set_time_zone( $self->_get_cached_tz($tz) );
67 }
68 else {
69 warn sprintf '%s had null timezone (%s): using UTC',
70 1 $info->{__dbic_colname}, $tz_src;
71 }
72 }
73  
74 3 return $dt;
75 }
76  
77 7 ▶sub _pre_deflate_datetime {
Subroutine _pre_deflate_datetime: called CC=3 SCAR=11.0
78 7 my ( $self, $dt, $info ) = @_;
79  
80 7 ▶ if ( my $tz_src = $info->{timezone_source} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tz_src = $info->{"timezone_source"}) 7 0 7
81 7 $self->set_column( $tz_src, $dt->time_zone->name );
82 }
83  
84 7 ▶ if ( !$ENV{DBIC_IC_DT_WTZ_MODIFY_TZ} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"DBIC_IC_DT_WTZ_MODIFY_TZ"}) 5 2 7
85 5 $dt = $dt->clone;
86 }
87  
88 7 $dt = $self->next::method( $dt, $info );
89  
90 7 return $dt;
91 }
92  
93 6 1;
94 __END__
↑ Summary