| 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
| |||||||||||
| 66 | 10 | bless $s,$class; | |||||||||
| 67 | |||||||||||
| 68 | 10 | ▶ | $s->{seconds} = exists $a{seconds} ? $a{seconds} : $sec; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 10 | ▶ | $s->{minutes} = exists $a{minutes} ? $a{minutes} : $min; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 10 | ▶ | $s->{hours} = exists $a{hours} ? $a{hours} : $hour; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 10 | ▶ | $s->{day} = exists $a{day} ? $a{day} : $mday; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 10 | ▶ | $s->{month} = exists $a{month} ? $a{month} : $mon; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 10 | ▶ | $s->{year} = exists $a{year} ? $a{year} : $year; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | 10 | ▶ | $s->{day_of_week} = exists $a{day_of_week} ? $a{day_of_week} : $wday; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | 10 | ▶ | $s->{day_of_year} = exists $a{day_of_year} ? $a{day_of_year} : $yday; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 10 | ▶ | $s->{is_dst} = exists $a{is_dst} ? $a{is_dst} : $isdst; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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; | |||||||||