lib/Reaction/UI/ViewPort/Field/TimeRange.pm

filter: Statementstmt 45.6% 26 / 57 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 46.1% 6 / 13 Podpod 75.0% 3 / 4 totaltotal 38.4% 35 / 91 CC 9 SCAR 30.5
CC
9
Cov
36%
range_to_spanset
56.0
adopt_value_string
12.0
__ANON__
2.0
CRAP 21.1
« lib/Reaction/UI/ViewPort/Role/FieldArgs.pm ↑ Summary lib/Reaction/UI/ViewPort/Collection.pm »
1 package Reaction::UI::ViewPort::Field::TimeRange;
2  
3 1 ▶use Reaction::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Reaction::Types::DateTime qw(SpanSet);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use DateTime::SpanSet;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Time::ParseDate ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use namespace::clean -except => [ qw(meta) ];
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 extends 'Reaction::UI::ViewPort::Field';
11  
12  
13  
14 1 has '+value' => (isa => SpanSet);
15  
16 #has '+layout' => (default => 'timerange');
17  
18 1 has value_string =>
19 (isa => 'Str', is => 'rw', lazy_fail => 1, trigger_adopt('value_string'));
20  
21 has delete_label => (
22 0 ▶ isa => 'Str', is => 'rw', required => 1, default => sub { 'Delete' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
23 1 );
24  
25 1 has parent => (
26 isa => 'Reaction::UI::ViewPort::TimeRangeCollection',
27 is => 'ro',
28 required => 1,
29 weak_ref => 1
30 );
31 0 ▶sub _build_value_string {
Subroutine _build_value_string: not called CC=1 SCAR=6.9
32 0 my $self = shift;
33 #return '' unless $self->has_value;
34 #return $self->value_string;
35 };
36 0 ▶sub value_array {
Subroutine value_array: not called CC=1 SCAR=6.9
Pod documented
37 0 my $self = shift;
38 0 return split(',', $self->value_string);
39 };
40 0 ▶sub adopt_value_string {
Subroutine adopt_value_string: not called CC=3 SCAR=24.8
Pod undocumented
41 0 my ($self) = @_;
42 0 my @values = $self->value_array;
43 0 for my $idx (0 .. 3) { # last value is repeat
44 0 ▶ if (length $values[$idx]) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $values[$idx]) 0 0 0
45 0 my ($epoch) = Time::ParseDate::parsedate($values[$idx], UK => 1);
46 0 $values[$idx] = DateTime->from_epoch( epoch => $epoch );
47 }
48 }
49 0 $self->value($self->range_to_spanset(@values));
50 };
51 0 ▶sub range_to_spanset {
Subroutine range_to_spanset: not called CC=7 SCAR=40.3
Pod documented
52 0 my ($self, $time_from, $time_to, $repeat_from, $repeat_to, $pattern) = @_;
53 0 my $spanset = DateTime::SpanSet->empty_set;
54 0 ▶ if (!$pattern || $pattern eq 'none') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $pattern or $pattern eq 'none') { } 0 0 0
Condition0%0/3
not $pattern or $pattern eq "none"
l!l&&r!l&&!r
000
MC/DC0%0/2
not $pattern or $pattern eq "none"
not $pattern $pattern eq "none"
Truth table0%0/3
not(A) or B
A= not $patternB= $pattern eq "none"
ABresult
1X1
011
000
55 0 my $span = DateTime::Span->from_datetimes(
56 start => $time_from, end => $time_to
57 );
58 0 $spanset = $spanset->union( $span );
59 } else {
60 0 my $duration = $time_to - $time_from;
61 0 my %args = ( days => $time_from->day + 2,
62 hours => $time_from->hour,
63 minutes => $time_from->minute,
64 seconds => $time_from->second );
65  
66 0 ▶ delete $args{'days'} if ($pattern eq 'daily');
Branch: 1 branch
BranchTrueFalseTotal
if $pattern eq "daily" 0 0 0
67 0 ▶ delete @args{qw/hours days/} if ($pattern eq 'hourly');
Branch: 1 branch
BranchTrueFalseTotal
if $pattern eq "hourly" 0 0 0
68 0 ▶ $args{'days'} = $time_from->day if ($pattern eq 'monthly');
Branch: 1 branch
BranchTrueFalseTotal
if $pattern eq "monthly" 0 0 0
69 0 my $start_set = DateTime::Event::Recurrence->$pattern( %args );
70 0 my $iter = $start_set->iterator( start => $repeat_from, end => $repeat_to );
71 0 ▶ while ( my $dt = $iter->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dt = $iter->next) 0 0 0
72 0 my $endtime = $dt + $duration;
73 0 my $new_span = DateTime::Span->from_datetimes(
74 start => $dt,
75 end => $endtime
76 );
77 0 $spanset = $spanset->union( $new_span );
78 }
79 }
80 0 return $spanset;
81 };
82 0 ▶sub delete {
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
83 0 my ($self) = @_;
84 0 $self->parent->remove_range_vp($self);
85 };
86  
87 0 ▶override accept_events => sub { ('value_string', 'delete', super()) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
88  
89 1 __PACKAGE__->meta->make_immutable;
90  
91  
92 1 1;
93  
94 =head1 NAME
95  
96 Reaction::UI::ViewPort::Field::TimeRange
97  
98 =head1 SYNOPSIS
99  
100 =head1 DESCRIPTION
101  
102 =head1 METHODS
103  
104 =head2 value
105  
106 Accessor for a L<DateTime::SpanSet> object.
107  
108 =head2 value_string
109  
110 Returns: Encoded range string representing the value.
111  
112 =head2 value_array
113  
114 Returns: Arrayref of the elements of C<value_string>.
115  
116 =head2 parent
117  
118 L<Reaction::UI::ViewPort::TimeRangeCollection> object.
119  
120 =head2 range_to_spanset
121  
122 Arguments: $self, $time_from, $time_to, $repeat_from, $repeat_to, $pattern
123 where $time_from, $time_to, $repeat_from, $repeat_to are L<DateTime>
124 objects, and $pattern is a L<DateTime::Event::Recurrence> method name
125  
126 Returns: $spanset
127  
128 =head2 delete
129  
130 Removes TimeRange from C<parent> collection.
131  
132 =head2 delete_label
133  
134 Label for the delete option. Default: 'Delete'.
135  
136 =head1 SEE ALSO
137  
138 =head2 L<Reaction::UI::ViewPort::Field>
139  
140 =head2 L<Reaction::UI::ViewPort::TimeRangeCollection>
141  
142 =head1 AUTHORS
143  
144 See L<Reaction::Class> for authors.
145  
146 =head1 LICENSE
147  
148 See L<Reaction::Class> for the license.
149  
150 =cut
« lib/Reaction/UI/ViewPort/Role/FieldArgs.pm ↑ Summary lib/Reaction/UI/ViewPort/Collection.pm »