| 1 | package Time::Vector; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Time::Simple::Range; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Time::Seconds; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Bit::Vector::Overload; # this thingy can't be subclassed :( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use base qw/ Class::Accessor::Fast /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | use overload | ||||||||||||||||||||||||||||
| 12 | 1 | ▶ | 'fallback' => 0, | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | '&' => 'and', | ||||||||||||||||||||||||||||
| 14 | '|' => 'or', | ||||||||||||||||||||||||||||
| 15 | '=' => 'clone', | ||||||||||||||||||||||||||||
| 16 | 1 | '""' => 'stringify'; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | our $VERSION = '1.1'; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | __PACKAGE__->mk_accessors(qw/ vec first last /); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use constant BITS_PER_DAY => 1440; # 1 bit per minute | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | sub new | ||||||||||||||||||||||||||||
| 26 | 9 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 9 | my ($proto, $vec) = @_; | |||||||||||||||||||||||||||
| 28 | 9 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 9 | my $self = bless $proto->SUPER::new(), $class; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 9 | ▶ | $self->vec(defined $vec ? $vec : Bit::Vector->new(BITS_PER_DAY)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 9 | $self->first(undef); | |||||||||||||||||||||||||||
| 34 | 9 | $self->last(undef); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 9 | return bless $self, $class; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | sub new_range | ||||||||||||||||||||||||||||
| 40 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new_range: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | 5 | my ($proto, @range) = @_; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 5 | my $self = new Time::Vector; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 5 | ▶ | while (scalar @range >= 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 6 | my @r = splice(@range, 0, 2); | |||||||||||||||||||||||||||
| 47 | 6 | $self->add_range(Time::Simple::Range->new($r[0], $r[1])); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 5 | return $self; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | sub add_range | ||||||||||||||||||||||||||||
| 55 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
add_range: called CC=6 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 56 | 6 | my ($self, $range) = @_; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 6 | my $start = $range->start->hours * 60 + $range->start->minutes; | |||||||||||||||||||||||||||
| 59 | 6 | my $end = $range->end->hours * 60 + $range->end->minutes; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 6 | ▶ | $end-- | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | unless $range->end->seconds == 59; | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 6 | ▶ | $self->first($range->start) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $self->first or $range->start < $self->first
MC/DC50%1/2
not defined $self->first or $range->start < $self->first
not defined $self->first
$range->start < $self->first
Truth table66%2/3
not(A) or B
A= not defined $self->firstB= $range->start < $self->first
| |||||||||||||||||||||||||||||
| 65 | if not defined $self->first | ||||||||||||||||||||||||||||
| 66 | or $range->start < $self->first; | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 6 | ▶ | $self->last($range->end) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $self->last or $range->end > $self->last
MC/DC0%0/2
not defined $self->last or $range->end > $self->last
not defined $self->last
$range->end > $self->last
Truth table66%2/3
not(A) or B
A= not defined $self->lastB= $range->end > $self->last
| |||||||||||||||||||||||||||||
| 69 | if not defined $self->last | ||||||||||||||||||||||||||||
| 70 | or $range->end > $self->last; | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # Bitwise OR between old vector and range vector | ||||||||||||||||||||||||||||
| 73 | 6 | my $nv = $self->vec | Bit::Vector->new_Enum(BITS_PER_DAY, "$start-$end"); | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 6 | $self->vec($nv); | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | sub after | ||||||||||||||||||||||||||||
| 79 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
after: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 80 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 81 | 1 | ▶ | return undef unless defined $self->last; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 1 | return Time::Vector->new_range($self->last, Time::Simple->new('23:59:59')); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | sub before | ||||||||||||||||||||||||||||
| 86 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
before: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 87 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 88 | 1 | ▶ | return undef unless defined $self->first; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 1 | return Time::Vector->new_range(Time::Simple->new('00:00:00'), $self->first); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | sub range | ||||||||||||||||||||||||||||
| 93 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
range: called CC=4 SCAR=15.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 94 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 95 | 3 | my @range; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 3 | my $base = Time::Simple->new('00:00:00'); | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 3 | my $enum = $self->vec->to_Enum; | |||||||||||||||||||||||||||
| 100 | 3 | foreach my $r (split(/,/, $enum)) { | |||||||||||||||||||||||||||
| 101 | 6 | ▶ | if ($r =~ /^(\d+)-(\d+)$/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 102 | 6 | my $s = $base + ($1 * 60); | |||||||||||||||||||||||||||
| 103 | 6 | my $e = $base + ($2 * 60) + 60; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 6 | push(@range, Time::Simple::Range->new($s, $e)); | |||||||||||||||||||||||||||
| 106 | } elsif ($r =~ /^(\d+)$/) { | ||||||||||||||||||||||||||||
| 107 | 0 | my $s = $base + ($1 * 60); | |||||||||||||||||||||||||||
| 108 | 0 | my $e = $s + 60; | |||||||||||||||||||||||||||
| 109 | 0 | push(@range, Time::Simple::Range->new($s, $e)); | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 3 | return @range; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | sub duration | ||||||||||||||||||||||||||||
| 117 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
duration: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 118 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 119 | 2 | my $d = 0; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 2 | foreach ($self->range) { | |||||||||||||||||||||||||||
| 122 | 4 | $d += $_->duration; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 2 | return new Time::Seconds($d); | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | sub and | ||||||||||||||||||||||||||||
| 129 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
and: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 130 | 1 | my ($a, $b) = @_; | |||||||||||||||||||||||||||
| 131 | 1 | my $vec = $a->vec & $b->vec; | |||||||||||||||||||||||||||
| 132 | 1 | return Time::Vector->new($vec); | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | sub or | ||||||||||||||||||||||||||||
| 136 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
or: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 137 | 1 | my ($a, $b) = @_; | |||||||||||||||||||||||||||
| 138 | 1 | my $vec = $a->vec | $b->vec; | |||||||||||||||||||||||||||
| 139 | 1 | return Time::Vector->new($vec); | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | sub stringify | ||||||||||||||||||||||||||||
| 143 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 144 | return join(',', map { | ||||||||||||||||||||||||||||
| 145 | 1 | $_->start->format('%H:%M') | |||||||||||||||||||||||||||
| 146 | . '-' | ||||||||||||||||||||||||||||
| 147 | . $_->end->format('%H:%M') | ||||||||||||||||||||||||||||
| 148 | } (shift)->range); | ||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | sub clone | ||||||||||||||||||||||||||||
| 152 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 153 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 154 | 1 | return Time::Vector->new($self->vec->Clone); | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 1 | 1; | |||||||||||||||||||||||||||