Fey/Role/SQL/HasLimitClause.pm

filter: Statementstmt 100% 37 / 37 Branchbran 100% 12 / 12 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 100% 70 / 70 CC 9 SCAR 13.4
CC
9
Cov
100%
limit_clause
7.0
limit
3.0
BEGIN
1.0
CRAP 3.8
« Fey/SQL/Update.pm ↑ Summary Fey/SQL/Insert.pm »
1 package Fey::Role::SQL::HasLimitClause;
2  
3 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 27 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 27 our $VERSION = '0.44';
8  
9 27 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 27 ▶use Fey::Types qw( PosInteger PosOrZeroInteger Undef );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 27 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 27 ▶use MooseX::Params::Validate 0.21 qw( pos_validated_list );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 27 has '_limit' => (
17 is => 'rw',
18 writer => '_set_limit',
19 predicate => '_has_limit',
20 );
21  
22 27 has '_offset' => (
23 is => 'rw',
24 writer => '_set_offset',
25 predicate => '_has_offset',
26 );
27  
28 8 ▶sub limit {
Subroutine limit: called CC=3 SCAR=11.0
Pod documented
29 8 my $self = shift;
30 8 my ( $limit, $offset ) = pos_validated_list(
31 \@_,
32 { isa => ( PosInteger | Undef ) },
33 {
34 isa => PosOrZeroInteger,
35 optional => 1,
36 },
37 );
38  
39 7 ▶ $self->_set_limit($limit)
Branch: 1 branch
BranchTrueFalseTotal
if defined $limit 6 1 7
40 if defined $limit;
41 7 ▶ $self->_set_offset($offset)
Branch: 1 branch
BranchTrueFalseTotal
if defined $offset 2 5 7
42 if defined $offset;
43  
44 7 return $self;
45 }
46  
47 110 ▶sub limit_clause {
Subroutine limit_clause: called CC=7 SCAR=19.5
Pod documented
48 110 my $self = shift;
49  
50 110 ▶ return unless $self->_has_limit() || $self->_has_offset();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_has_limit or $self->_has_offset 103 7 110
Condition100%3/3
$self->_has_limit or $self->_has_offset
l!l&&r!l&&!r
61103
MC/DC100%2/2
$self->_has_limit or $self->_has_offset
$self->_has_limit $self->_has_offset
Truth table100%3/3
A or B
A= $self->_has_limitB= $self->_has_offset
ABresult
1X1
011
000
51  
52 7 my $sql = '';
53  
54 7 ▶ $sql .= 'LIMIT ' . $self->_limit()
Branch: 1 branch
BranchTrueFalseTotal
if $self->_has_limit 6 1 7
55 if $self->_has_limit();
56 7 ▶ $sql .= q{ }
Branch: 1 branch
BranchTrueFalseTotal
if $self->_has_limit and $self->_has_offset 1 6 7
Condition100%3/3
$self->_has_limit and $self->_has_offset
!ll&&!rl&&r
151
MC/DC100%2/2
$self->_has_limit and $self->_has_offset
$self->_has_limit $self->_has_offset
Truth table100%3/3
A and B
A= $self->_has_limitB= $self->_has_offset
ABresult
0X0
100
111
57 if $self->_has_limit() && $self->_has_offset();
58 7 ▶ $sql .= 'OFFSET ' . $self->_offset()
Branch: 1 branch
BranchTrueFalseTotal
if $self->_has_offset 2 5 7
59 if $self->_has_offset();
60  
61 7 return $sql;
62 }
63  
64 27 1;
65  
66 # ABSTRACT: A role for queries which can include a LIMIT clause
67  
68 __END__
« Fey/SQL/Update.pm ↑ Summary Fey/SQL/Insert.pm »