App/Dochazka/REST/Model/Tempintvl.pm

filter: Statementstmt 50.0% 28 / 56 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 75.0% 9 / 12 Podpod 100% 3 / 3 totaltotal 38.1% 40 / 105 CC 11 SCAR 39.3
CC
11
Cov
34%
fetch_tempintvls_by_tiid_and_tsrange
110.0
delete
6.0
insert
2.0
CRAP 51.0
« App/Dochazka/REST/Model/Schedule.pm ↑ Summary App/Dochazka/REST/LDAP.pm »
1 # *************************************************************************
2 # Copyright (c) 2014-2017, SUSE LLC
3 #
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
8 #
9 # 1. Redistributions of source code must retain the above copyright notice,
10 # this list of conditions and the following disclaimer.
11 #
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 #
16 # 3. Neither the name of SUSE LLC nor the names of its contributors may be
17 # used to endorse or promote products derived from this software without
18 # specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 # POSSIBILITY OF SUCH DAMAGE.
31 # *************************************************************************
32  
33 package App::Dochazka::REST::Model::Tempintvl;
34  
35 41 ▶use 5.012;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 41 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 41 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 41 ▶use App::CELL qw( $CELL $log $site );
Subroutine BEGIN: called CC=1 SCAR=0.0
40 41 ▶use App::Dochazka::REST::Model::Shared qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
41 canonicalize_tsrange
42 cud
43 load_multiple
44 tsrange_intersection
45 41 );
46 41 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 41 ▶use Params::Validate qw( :all );
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 # we get 'spawn', 'reset', and accessors from parent
50 41 ▶use parent 'App::Dochazka::Common::Model::Tempintvl';
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52  
53  
54  
55 =head1 NAME
56  
57 App::Dochazka::REST::Model::Tempintvl - tempintvl data model
58  
59  
60  
61  
62 =head1 SYNOPSIS
63  
64 use App::Dochazka::REST::Model::Tempintvl;
65  
66 ...
67  
68  
69 =head1 DESCRIPTION
70  
71 A description of the tempinvl data model follows.
72  
73  
74 =head2 Tempintvls in the database
75  
76 CREATE TABLE tempintvls (
77 int_id serial PRIMARY KEY,
78 tiid integer NOT NULL,
79 intvl tstzrange NOT NULL
80 )
81  
82  
83  
84 =head1 EXPORTS
85  
86 This module provides the following exports:
87  
88 =cut
89  
90 41 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
91 41 our @EXPORT_OK = qw(
92 fetch_tempintvls_by_tiid_and_tsrange
93 );
94  
95  
96  
97 =head1 METHODS
98  
99  
100 =head2 delete
101  
102 Attempts to the delete the record (in the tempintvls table) corresponding
103 to the object. Returns a status object.
104  
105 =cut
106  
107 0 ▶sub delete {
Subroutine delete: not called CC=2 SCAR=17.9
Pod documented
108 0 my $self = shift;
109 0 my ( $context ) = validate_pos( @_, { type => HASHREF } );
110  
111 my $status = cud(
112 conn => $context->{'dbix_conn'},
113 0 eid => $context->{'current'}->{'eid'},
114 object => $self,
115 sql => $site->SQL_TEMPINTVL_DELETE_SINGLE,
116 attrs => [ 'int_id' ],
117 );
118 0 ▶ $self->reset( int_id => $self->{int_id} ) if $status->ok;
Branch: 1 branch
BranchTrueFalseTotal
if $status->ok 0 0 0
119  
120 0 return $status;
121 }
122  
123  
124 =head2 insert
125  
126 Instance method. Attempts to INSERT a record. Field values are taken from the
127 object. Returns a status object.
128  
129 =cut
130  
131 0 ▶sub insert {
Subroutine insert: not called CC=1 SCAR=6.9
Pod documented
132 0 my $self = shift;
133 0 my ( $context ) = validate_pos( @_, { type => HASHREF } );
134  
135 my $status = cud(
136 conn => $context->{'dbix_conn'},
137 0 eid => $context->{'current'}->{'eid'},
138 object => $self,
139 sql => $site->SQL_TEMPINTVL_INSERT,
140 attrs => [ 'tiid', 'intvl' ],
141 );
142  
143 0 return $status;
144 }
145  
146  
147  
148 =head1 FUNCTIONS
149  
150  
151 =head2 fetch_tempintvls_by_tiid_and_tsrange
152  
153 Given a L<DBIx::Connector> object, a tiid and a tsrange, return the set
154 (array) of C<tempintvl> objects that match the tiid and tsrange.
155  
156 =cut
157  
158 0 ▶sub fetch_tempintvls_by_tiid_and_tsrange {
Subroutine fetch_tempintvls_by_tiid_and_tsrange: not called CC=10 SCAR=47.0
Pod documented
159 0 my ( $conn, $tiid, $tsrange ) = validate_pos( @_,
160 { isa => 'DBIx::Connector' },
161 { type => SCALAR },
162 { type => SCALAR },
163 );
164  
165 0 my $status = canonicalize_tsrange( $conn, $tsrange );
166 0 ▶ return $status unless $status->ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $status->ok 0 0 0
167 0 $tsrange = $status->payload;
168  
169 0 $status = load_multiple(
170 conn => $conn,
171 class => __PACKAGE__,
172 sql => $site->SQL_TEMPINTVLS_SELECT_BY_TIID_AND_TSRANGE,
173 keys => [ $tiid, $tsrange, $site->DOCHAZKA_INTERVAL_SELECT_LIMIT ],
174 );
175 0 ▶ return $status unless
Branch: 1 branch
BranchTrueFalseTotal
unless $status->ok and $status->code eq "DISPATCH_RECORDS_FOUND" or $status->level eq "NOTICE" and $status->code eq "DISPATCH_NO_RECORDS_FOUND" 0 0 0
Condition0%0/9
$status->ok and $status->code eq "DISPATCH_RECORDS_FOUND" or $status->level eq "NOTICE" and $status->code eq "DISPATCH_NO_RECORDS_FOUND"
l!l&&r!l&&!r
000
$status->ok and $status->code eq "DISPATCH_RECORDS_FOUND"
!ll&&!rl&&r
000
$status->level eq "NOTICE" and $status->code eq "DISPATCH_NO_RECORDS_FOUND"
!ll&&!rl&&r
000
MC/DC0%0/4
$status->ok and $status->code eq "DISPATCH_RECORDS_FOUND" or $status->level eq "NOTICE" and $status->code eq "DISPATCH_NO_RECORDS_FOUND"
$status->ok $status->code eq "DISPATCH_RECORDS_FOUND" $status->level eq "NOTICE" $status->code eq "DISPATCH_NO_RECORDS_FOUND"
Truth table0%0/7
A and B or C and D
A= $status->okB= $status->code eq "DISPATCH_RECORDS_FOUND"C= $status->level eq "NOTICE"D= $status->code eq "DISPATCH_NO_RECORDS_FOUND"
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
176 ( $status->ok and $status->code eq 'DISPATCH_RECORDS_FOUND' ) or
177 ( $status->level eq 'NOTICE' and $status->code eq 'DISPATCH_NO_RECORDS_FOUND' );
178 0 my $whole_intervals = $status->payload;
179  
180 0 $status = load_multiple(
181 conn => $conn,
182 class => __PACKAGE__,
183 sql => $site->SQL_TEMPINTVLS_SELECT_BY_TIID_AND_TSRANGE_PARTIAL_INTERVALS,
184 keys => [ $tiid, $tsrange, $tiid, $tsrange ],
185 );
186 0 ▶ return $status unless
Branch: 1 branch
BranchTrueFalseTotal
unless $status->ok and $status->code eq "DISPATCH_RECORDS_FOUND" or $status->level eq "NOTICE" and $status->code eq "DISPATCH_NO_RECORDS_FOUND" 0 0 0
Condition0%0/9
$status->ok and $status->code eq "DISPATCH_RECORDS_FOUND" or $status->level eq "NOTICE" and $status->code eq "DISPATCH_NO_RECORDS_FOUND"
l!l&&r!l&&!r
000
$status->ok and $status->code eq "DISPATCH_RECORDS_FOUND"
!ll&&!rl&&r
000
$status->level eq "NOTICE" and $status->code eq "DISPATCH_NO_RECORDS_FOUND"
!ll&&!rl&&r
000
MC/DC0%0/4
$status->ok and $status->code eq "DISPATCH_RECORDS_FOUND" or $status->level eq "NOTICE" and $status->code eq "DISPATCH_NO_RECORDS_FOUND"
$status->ok $status->code eq "DISPATCH_RECORDS_FOUND" $status->level eq "NOTICE" $status->code eq "DISPATCH_NO_RECORDS_FOUND"
Truth table0%0/7
A and B or C and D
A= $status->okB= $status->code eq "DISPATCH_RECORDS_FOUND"C= $status->level eq "NOTICE"D= $status->code eq "DISPATCH_NO_RECORDS_FOUND"
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
187 ( $status->ok and $status->code eq 'DISPATCH_RECORDS_FOUND' ) or
188 ( $status->level eq 'NOTICE' and $status->code eq 'DISPATCH_NO_RECORDS_FOUND' );
189 0 my $partial_intervals = $status->payload;
190  
191 map
192 {
193 0 $_->intvl(
194 tsrange_intersection( $conn, $tsrange, $_->intvl )
195 );
196 } ( @$partial_intervals );
197
198 0 my @result_set = ();
199 0 push @result_set, @$whole_intervals, @$partial_intervals;
200  
201 # But now the intervals are out of order
202 0 my @sorted_tmpintvls = sort { $a->intvl cmp $b->intvl } @result_set;
203 0 return \@sorted_tmpintvls;
204  
205 0 return \sort { $a->intvl cmp $b->intvl } @result_set;
206  
207 }
208  
209  
210  
211 =head1 AUTHOR
212  
213 Nathan Cutler, C<< <presnypreklad@gmail.com> >>
214  
215 =cut
216  
217 41 1;
218  
219  
« App/Dochazka/REST/Model/Schedule.pm ↑ Summary App/Dochazka/REST/LDAP.pm »