| 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
| |||||||||||||||||||||||||||||
| 40 | if defined $limit; | ||||||||||||||||||||||||||||
| 41 | 7 | ▶ | $self->_set_offset($offset) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$self->_has_limit or $self->_has_offset
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
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 7 | my $sql = ''; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 7 | ▶ | $sql .= 'LIMIT ' . $self->_limit() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | if $self->_has_limit(); | ||||||||||||||||||||||||||||
| 56 | 7 | ▶ | $sql .= q{ } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->_has_limit and $self->_has_offset
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
| |||||||||||||||||||||||||||||
| 57 | if $self->_has_limit() && $self->_has_offset(); | ||||||||||||||||||||||||||||
| 58 | 7 | ▶ | $sql .= 'OFFSET ' . $self->_offset() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||