Lyskom/Time.pm

filter: Statementstmt 63.0% 46 / 73 Branchbran 27.5% 11 / 40 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 52.6% 10 / 19 Podpod 92.3% 12 / 13 totaltotal 54.4% 79 / 145 CC 21 SCAR 19.3
CC
21
Cov
50%
new
13.6
seconds
6.0
minutes
6.0
CRAP 6.9
« Lyskom/MiscInfo.pm ↑ Summary Lyskom/TextStat.pm »
1 package Net::Lyskom::Time;
2 1 ▶use base qw{Net::Lyskom::Object};
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 Net::Lyskom::Time - object that holds a time value.
14  
15 =head1 SYNOPSIS
16  
17 print scalar localtime($obj->time_t);
18  
19 =head1 DESCRIPTION
20  
21 All methods except time_t() and new() are get/set attribute accessors. That
22 is, they return the attribute's contents if called without an argument and
23 set the attribute's contents if given an argument. time_t() returns the held
24 time in seconds since the Unix epoch, and new() creates a new object.
25  
26 =head2 Methods
27  
28 =over
29  
30 =item ->new(seconds => $s, minutes => $m, hours => $h, day => $d, month => $mo, year => $y, day_of_week => $wd, day_of_year => $yd, is_dst => $dst)
31  
32 All arguments are optional. If not given, they default to the value appropriate
33 to the current time.
34  
35 =item ->seconds($s)
36  
37 =item ->minutes($m)
38  
39 =item ->hours($h)
40  
41 =item ->day($d)
42  
43 =item ->month($mo)
44  
45 =item ->year($y)
46  
47 =item ->day_of_week($wd)
48  
49 =item ->day_of_year($yd)
50  
51 =item ->is_dst($dst)
52  
53 =item ->time_t()
54  
55 =back
56  
57 =cut
58  
59 10 ▶sub new {
Subroutine new: called CC=11 SCAR=26.1
Pod documented
60 10 my $s = {};
61 10 my $class = shift;
62 10 my %a = @_;
63 10 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
64  
65 10 ▶ $class = ref($class) if ref($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 10 10
66 10 bless $s,$class;
67  
68 10 ▶ $s->{seconds} = exists $a{seconds} ? $a{seconds} : $sec;
Branch: 1 branch
BranchTrueFalseTotal
exists $a{'seconds'} ? : 10 0 10
69 10 ▶ $s->{minutes} = exists $a{minutes} ? $a{minutes} : $min;
Branch: 1 branch
BranchTrueFalseTotal
exists $a{'minutes'} ? : 10 0 10
70 10 ▶ $s->{hours} = exists $a{hours} ? $a{hours} : $hour;
Branch: 1 branch
BranchTrueFalseTotal
exists $a{'hours'} ? : 10 0 10
71 10 ▶ $s->{day} = exists $a{day} ? $a{day} : $mday;
Branch: 1 branch
BranchTrueFalseTotal
exists $a{'day'} ? : 10 0 10
72 10 ▶ $s->{month} = exists $a{month} ? $a{month} : $mon;
Branch: 1 branch
BranchTrueFalseTotal
exists $a{'month'} ? : 10 0 10
73 10 ▶ $s->{year} = exists $a{year} ? $a{year} : $year;
Branch: 1 branch
BranchTrueFalseTotal
exists $a{'year'} ? : 10 0 10
74 10 ▶ $s->{day_of_week} = exists $a{day_of_week} ? $a{day_of_week} : $wday;
Branch: 1 branch
BranchTrueFalseTotal
exists $a{'day_of_week'} ? : 10 0 10
75 10 ▶ $s->{day_of_year} = exists $a{day_of_year} ? $a{day_of_year} : $yday;
Branch: 1 branch
BranchTrueFalseTotal
exists $a{'day_of_year'} ? : 10 0 10
76 10 ▶ $s->{is_dst} = exists $a{is_dst} ? $a{is_dst} : $isdst;
Branch: 1 branch
BranchTrueFalseTotal
exists $a{'is_dst'} ? : 10 0 10
77  
78 10 return $s;
79 }
80  
81 10 ▶sub new_from_stream {
Subroutine new_from_stream: called CC=1 SCAR=0.0
Pod undocumented
82 10 my $s = shift;
83 10 my $arg = $_[0];
84  
85 10 my $res = $s->new(
86 seconds => $arg->[0],
87 minutes => $arg->[1],
88 hours => $arg->[2],
89 day => $arg->[3],
90 month => $arg->[4],
91 year => $arg->[5],
92 day_of_week => $arg->[6],
93 day_of_year => $arg->[7],
94 is_dst => $arg->[8]
95 );
96 10 splice @{$arg},0,9;
97 10 return $res;
98 }
99  
100 0 ▶sub seconds {
Subroutine seconds: not called CC=2 SCAR=17.9
Pod documented
101 0 my $s = shift;
102  
103 0 ▶ $s->{seconds} = $_[0] if $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 0 0 0
104 0 return $s->{seconds};
105 }
106  
107 0 ▶sub minutes {
Subroutine minutes: not called CC=2 SCAR=17.9
Pod documented
108 0 my $s = shift;
109  
110 0 ▶ $s->{minutes} = $_[0] if $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 0 0 0
111 0 return $s->{minutes};
112 }
113  
114 0 ▶sub hours {
Subroutine hours: not called CC=2 SCAR=17.9
Pod documented
115 0 my $s = shift;
116  
117 0 ▶ $s->{hours} = $_[0] if $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 0 0 0
118 0 return $s->{hours};
119 }
120  
121 0 ▶sub day {
Subroutine day: not called CC=2 SCAR=17.9
Pod documented
122 0 my $s = shift;
123  
124 0 ▶ $s->{day} = $_[0] if $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 0 0 0
125 0 return $s->{day};
126 }
127  
128 0 ▶sub month {
Subroutine month: not called CC=2 SCAR=17.9
Pod documented
129 0 my $s = shift;
130  
131 0 ▶ $s->{month} = $_[0] if $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 0 0 0
132 0 return $s->{month};
133 }
134  
135 0 ▶sub year {
Subroutine year: not called CC=2 SCAR=17.9
Pod documented
136 0 my $s = shift;
137  
138 0 ▶ $s->{year} = $_[0] if $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 0 0 0
139 0 return $s->{year};
140 }
141  
142 0 ▶sub day_of_week {
Subroutine day_of_week: not called CC=2 SCAR=17.9
Pod documented
143 0 my $s = shift;
144  
145 0 ▶ $s->{day_of_week} = $_[0] if $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 0 0 0
146 0 return $s->{day_of_week};
147 }
148  
149 0 ▶sub day_of_year {
Subroutine day_of_year: not called CC=2 SCAR=17.9
Pod documented
150 0 my $s = shift;
151  
152 0 ▶ $s->{day_of_year} = $_[0] if $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 0 0 0
153 0 return $s->{day_of_year};
154 }
155  
156 0 ▶sub is_dst {
Subroutine is_dst: not called CC=2 SCAR=17.9
Pod documented
157 0 my $s = shift;
158  
159 0 ▶ $s->{is_dst} = $_[0] if $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 0 0 0
160 0 return $s->{is_dst};
161 }
162  
163 2 ▶sub time_t {
Subroutine time_t: called CC=2 SCAR=7.1
Pod documented
164 2 my $s = shift;
165  
166 $s->{time_t} = timelocal($s->{seconds},$s->{minutes},$s->{hours},
167 $s->{day},$s->{month},$s->{year})
168 2 ▶ unless exists($s->{time_t});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $s->{"time_t"} 2 0 2
169  
170 2 return $s->{time_t};
171 }
172  
173 1 ▶sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
174 1 my $s = shift;
175  
176 1 return "Time => { ".scalar(localtime($s->time_t))." }";
177 }
178  
179 1 return 1;
« Lyskom/MiscInfo.pm ↑ Summary Lyskom/TextStat.pm »