Fey/Role/SQL/HasOrderByClause.pm

filter: Statementstmt 100% 41 / 41 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 100% 61 / 61 CC 6 SCAR 9.0
CC
6
Cov
100%
order_by_clause
5.0
order_by
2.0
BEGIN
1.0
CRAP 2.5
« Fey/FK.pm ↑ Summary Fey/Literal.pm »
1 package Fey::Role::SQL::HasOrderByClause;
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 Fey::Types qw( ArrayRef OrderByElement );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 27 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 27 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 27 ▶use MooseX::Params::Validate 0.21 qw( pos_validated_list );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 has '_order_by' => (
16 traits => ['Array'],
17 is => 'bare',
18 isa => ArrayRef,
19 216 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
20 27 handles => {
21 _add_order_by_elements => 'push',
22 _has_order_by_elements => 'count',
23 _order_by => 'elements',
24 },
25 init_arg => undef,
26 );
27  
28 19 ▶sub order_by {
Subroutine order_by: called CC=2 SCAR=6.9
Pod documented
29 19 my $self = shift;
30  
31 19 ▶ my $count = @_ ? @_ : 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 18 1 19
32 19 my (@by) = pos_validated_list(
33 \@_,
34 ( ( { isa => OrderByElement } ) x $count ),
35 MX_PARAMS_VALIDATE_NO_CACHE => 1,
36 );
37  
38 18 $self->_add_order_by_elements(@by);
39  
40 18 return $self;
41 }
42  
43 118 ▶sub order_by_clause {
Subroutine order_by_clause: called CC=5 SCAR=16.1
Pod documented
44 118 my $self = shift;
45 118 my $dbh = shift;
46  
47 118 ▶ return unless $self->_has_order_by_elements();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_has_order_by_elements 100 18 118
48  
49 18 my $sql = 'ORDER BY ';
50  
51 18 my @elt = $self->_order_by();
52  
53 18 for my $elt (@elt) {
54 27 ▶ if ( !blessed $elt ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not builtin::blessed($elt)) { } 7 20 27
55 7 $sql .= q{ } . uc $elt;
56 }
57 else {
58 20 ▶ $sql .= ', ' if $elt != $elt[0];
Branch: 1 branch
BranchTrueFalseTotal
if $elt != $elt[0] 2 18 20
59 20 $sql .= $elt->sql_or_alias($dbh);
60 }
61 }
62  
63 18 return $sql;
64 }
65  
66 27 1;
67  
68 # ABSTRACT: A role for queries which can include a ORDER BY clause
69  
70 __END__
« Fey/FK.pm ↑ Summary Fey/Literal.pm »