| 1 | package Fey::Role::SQL::HasLimitClause; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 26 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 26 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 26 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 26 | our $VERSION = '0.42'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 26 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 26 | ▶ | use Fey::Types qw( PosInteger PosOrZeroInteger Undef ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 26 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 26 | ▶ | use MooseX::Params::Validate 0.08 qw( pos_validated_list ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 26 | has '_limit' => ( | |||||||||||||||||||||||||||
| 17 | is => 'rw', | ||||||||||||||||||||||||||||
| 18 | writer => '_set_limit', | ||||||||||||||||||||||||||||
| 19 | predicate => '_has_limit', | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 26 | has '_offset' => ( | |||||||||||||||||||||||||||
| 23 | is => 'rw', | ||||||||||||||||||||||||||||
| 24 | writer => '_set_offset', | ||||||||||||||||||||||||||||
| 25 | predicate => '_has_offset', | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | sub limit { | ||||||||||||||||||||||||||||
| 29 | 8 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
limit: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 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 | sub limit_clause { | ||||||||||||||||||||||||||||
| 48 | 110 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
limit_clause: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 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 | 26 | 1; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # ABSTRACT: A role for queries which can include a LIMIT clause | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | __END__ | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =pod | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =head1 NAME | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | Fey::Role::SQL::HasLimitClause - A role for queries which can include a LIMIT clause | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =head1 VERSION | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | version 0.42 | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | use Moose 0.90; | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | with 'Fey::Role::SQL::HasLimitClause'; | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | Classes which do this role represent a query which can include a | ||||||||||||||||||||||||||||
| 89 | C<LIMIT> clause. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =head1 METHODS | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | This role provides the following methods: | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =head2 $query->limit() | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | See the L<Fey::SQL section on LIMIT Clauses|Fey::SQL/LIMIT Clauses> | ||||||||||||||||||||||||||||
| 98 | for more details. | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =head2 $query->limit_clause() | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | Returns the C<LIMIT> clause portion of the SQL statement as a string. | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =head1 BUGS | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | See L<Fey> for details on how to report bugs. | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | Dave Rolsky <autarch@urth.org> | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | This software is Copyright (c) 2011 - 2015 by Dave Rolsky. | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | This is free software, licensed under: | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | The Artistic License 2.0 (GPL Compatible) | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =cut | ||||||||||||||||||||||||||||