blib/lib/Astro/App/Satpass2/FormatTime.pm

filter: Statementstmt 89.8% 80 / 89 Branchbran 68.1% 15 / 22 Conditioncond 41.6% 5 / 12 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 87.5% 14 / 16 Podpod 100% 7 / 7 totaltotal 79.2% 122 / 154 CC 16 SCAR 11.5
CC
16
Cov
81%
round_time
6.5
format_datetime_width
4.0
_format_datetime_width_try
4.0
CRAP 3.2
« blib/lib/Astro/App/Satpass2/Macro.pm ↑ Summary blib/lib/Astro/App/Satpass2/Format/Template/Provider.pm »
1 package Astro::App::Satpass2::FormatTime;
2  
3 20 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 20 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 20 ▶use parent qw{ Astro::App::Satpass2::Copier };
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 20 ▶use Astro::App::Satpass2::Utils qw{ @CARP_NOT };
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 20 our $VERSION = '0.059';
15  
16 20 ▶use constant ROUND_TIME => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 my $delegate = eval {
19 20 require Astro::App::Satpass2::FormatTime::DateTime::Strftime;
20 0 require DateTime::TimeZone;
21 0 DateTime::TimeZone->new( name => 'local' );
22 0 'Astro::App::Satpass2::FormatTime::DateTime::Strftime';
23 20 ▶} || do {
Condition33%1/3
eval { do { require Astro::App::Satpass2::FormatTime::DateTime::Strftime; require DateTime::TimeZone; 'DateTime::TimeZone'->new('name', 'local'); 'Astro::App::Satpass2::FormatTime::DateTime::Strftime' } } || do { require Astro::App::Satpass2::FormatTime::POSIX::Strftime; 'Astro::App::Satpass2::FormatTime::POSIX::Strftime' }
l!l&&r!l&&!r
0200
MC/DC0%0/2
eval { do { require Astro::App::Satpass2::FormatTime::DateTime::Strftime; require DateTime::TimeZone; 'DateTime::TimeZone'->new('name', 'local'); 'Astro::App::Satpass2::FormatTime::DateTime::Strftime' } } || do { require Astro::App::Satpass2::FormatTime::POSIX::Strftime; 'Astro::App::Satpass2::FormatTime::POSIX::Strftime' }
eval { do { require Astro::App::Satpass2::FormatTime::DateTime::Strftime; require DateTime::TimeZone; 'DateTime::TimeZone'->new('name', 'local'); 'Astro::App::Satpass2::FormatTime::DateTime::Strftime' } } do { require Astro::App::Satpass2::FormatTime::POSIX::Strftime; 'Astro::App::Satpass2::FormatTime::POSIX::Strftime' }
Truth table33%1/3
A || B
A= eval { do { require Astro::App::Satpass2::FormatTime::DateTime::Strftime; require DateTime::TimeZone; 'DateTime::TimeZone'->new('name', 'local'); 'Astro::App::Satpass2::FormatTime::DateTime::Strftime' } }B= do { require Astro::App::Satpass2::FormatTime::POSIX::Strftime; 'Astro::App::Satpass2::FormatTime::POSIX::Strftime' }
ABresult
1X1
011
000
24 20 require Astro::App::Satpass2::FormatTime::POSIX::Strftime;
25 20 'Astro::App::Satpass2::FormatTime::POSIX::Strftime';
26 };
27  
28 34 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
29 34 my ( $class, %args ) = @_;
30 34 ▶ ref $class and $class = ref $class;
Branch: 1 branch
BranchTrueFalseTotal
ref $class and $class = ref $class 0 34 34
31  
32 34 ▶ __PACKAGE__ eq $class and $class = $delegate;
Branch: 1 branch
BranchTrueFalseTotal
__PACKAGE__ eq $class and $class = $delegate 32 2 34
33  
34 34 my $self = {
35 round_time => ROUND_TIME,
36 };
37 34 bless $self, $class;
38 34 $self->init( %args );
39 34 return $self;
40 }
41  
42 54 ▶sub attribute_names {
Subroutine attribute_names: called CC=1 SCAR=0.0
Pod documented
43 54 return ( qw{ gmt tz } );
44 }
45  
46 {
47  
48 20 my %skip = map { $_ => 1 } qw{ back_end };
49  
50 0 ▶ sub copy {
Subroutine copy: not called CC=1 SCAR=6.9
Pod documented
51 0 my ( $self, $copy ) = @_;
52 0 return $self->SUPER::copy( $copy, %skip );
53 }
54 }
55  
56 {
57 20 my $leader_re = qr{ @{[ __PACKAGE__ ]} :: }smxo;
58  
59 2 ▶ sub class_name_of_record {
Subroutine class_name_of_record: called CC=2 SCAR=7.6
Pod documented
60 2 my ( $self ) = @_;
61 2 ▶ ( my $name = ref $self || $self ) =~ s/ \A $leader_re //smx;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
200
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
62 2 return $name;
63 }
64 }
65  
66 20 ▶sub format_datetime { ## no critic (RequireFinalReturn)
Subroutine format_datetime: not called CC=1 SCAR=2.6
Pod documented
67 0 my ( $self ) = @_;
68 # ->weep() throws an exception.
69 0 $self->weep(
70 'Method format_datetime() must be overridden' );
71 }
72  
73 {
74  
75 20 my %cache;
76  
77 356 ▶ sub format_datetime_width {
Subroutine format_datetime_width: called CC=4 SCAR=13.9
Pod documented
78 356 my ( $self, $tplt, $gmt ) = @_;
79  
80 356 ▶ defined $gmt
Branch: 1 branch
BranchTrueFalseTotal
defined $gmt or $gmt = $self->gmt 0 356 356
81 or $gmt = $self->gmt();
82 356 ▶ $gmt = $gmt ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$gmt ? : 356 0 356
83  
84 356 my $class = ref $self;
85  
86 exists $cache{$class}{$tplt}[$gmt]
87 356 ▶ and return $cache{$class}{$tplt}[$gmt];
Branch: 1 branch
BranchTrueFalseTotal
exists $cache{$class}{$tplt}[$gmt] and return $cache{$class}{$tplt}[$gmt] 341 15 356
88  
89 15 my ( $time, $wid ) = $self->_format_datetime_width_try( $tplt, undef,
90 $gmt, year => 2100 );
91 15 ( $time, $wid ) = $self->_format_datetime_width_try( $tplt, $time,
92 $gmt, month => 1 .. 12 );
93 15 ( $time, $wid ) = $self->_format_datetime_width_try( $tplt, $time,
94 $gmt, day => 1 .. 7 );
95 15 ( $time, $wid ) = $self->_format_datetime_width_try( $tplt, $time,
96 $gmt, hour => 6, 18 );
97  
98 15 return ( $cache{$class}{$tplt}[$gmt] = $wid );
99 }
100  
101 }
102  
103 20 ▶sub _format_datetime_width_try {
Subroutine _format_datetime_width_try: called CC=4 SCAR=13.9
104 60 my ( $self, $tplt, $time, $gmt, $name, @try ) = @_;
105 60 my $wid;
106 my $max_trial;
107 60 foreach my $trial ( @try ) {
108 330 $time = $self->__format_datetime_width_adjust_object(
109 $time, $name, $trial, $gmt );
110 330 my $size = length $self->format_datetime( $tplt, $time );
111 330 ▶ defined $wid and $size <= $wid and next;
Branch: 1 branch
BranchTrueFalseTotal
defined $wid and $size <= $wid and next 270 60 330
Condition66%2/3
defined $wid and $size <= $wid
!ll&&!rl&&r
600270
MC/DC50%1/2
defined $wid and $size <= $wid
defined $wid $size <= $wid
Truth table66%2/3
A and B
A= defined $widB= $size <= $wid
ABresult
0X0
100
111
112 60 $wid = $size;
113 60 $max_trial = $trial;
114 }
115 60 $time = $self->__format_datetime_width_adjust_object( $time, $name,
116 $max_trial, $gmt );
117 60 return ( $time, $wid );
118 }
119  
120 {
121 20 my %valid = (
122 hour => 3600,
123 minute => 60,
124 second => 1,
125 none => undef,
126 );
127  
128 1037 ▶ sub round_time {
Subroutine round_time: called CC=5 SCAR=18.7
Pod documented
129 1037 my ( $self, @arg ) = @_;
130 1037 ▶ if ( @arg ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@arg) { } 298 739 1037
131 298 my $val = $arg[0];
132 298 ▶ if ( defined $val && $val =~ m/ [^0-9] /smx ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and $val =~ / [^0-9] /msx) 0 298 298
Condition33%1/3
defined $val and $val =~ / [^0-9] /msx
!ll&&!rl&&r
02980
MC/DC0%0/2
defined $val and $val =~ / [^0-9] /msx
defined $val $val =~ / [^0-9] /msx
Truth table33%1/3
A and B
A= defined $valB= $val =~ / [^0-9] /msx
ABresult
0X0
100
111
133 0 ▶ exists $valid{$val}
Branch: 1 branch
BranchTrueFalseTotal
exists $valid{$val} or $self->wail("Invalid rounding spec '${val}'") 0 0 0
134 or $self->wail( "Invalid rounding spec '$val'" );
135 0 $val = $valid{$val}
136 }
137 298 $self->{round_time} = $val;
138 298 return $self;
139 } else {
140 739 return $self->{round_time};
141 }
142 }
143 }
144  
145 20 ▶sub __round_time_value {
Subroutine __round_time_value: called CC=3 SCAR=11.0
146 618 my ( $self, $time ) = @_;
147 618 ▶ ref $time
Branch: 1 branch
BranchTrueFalseTotal
ref $time and return $time 330 288 618
148 and return $time;
149 288 ▶ if ( my $round = $self->round_time() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $round = $self->round_time) 288 0 288
150 288 $time = POSIX::floor( ( $time + $round / 2 ) / $round ) * $round;
151 }
152 288 return $time;
153 }
154  
155 20 __PACKAGE__->create_attribute_methods();
156  
157 20 1;
158  
159 __END__
« blib/lib/Astro/App/Satpass2/Macro.pm ↑ Summary blib/lib/Astro/App/Satpass2/Format/Template/Provider.pm »