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/Role/SetOperation.pm »
1 package Fey::Role::SQL::HasOrderByClause;
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 Fey::Types qw( ArrayRef OrderByElement );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 26 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 26 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 26 ▶use MooseX::Params::Validate 0.08 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 26 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 sub order_by {
29 19 ▶ my $self = shift;
Subroutine order_by: called CC=2 SCAR=6.9
Pod documented
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 sub order_by_clause {
44 118 ▶ my $self = shift;
Subroutine order_by_clause: called CC=5 SCAR=16.1
Pod documented
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 26 1;
67  
68 # ABSTRACT: A role for queries which can include a ORDER BY clause
69  
70 __END__
71  
72 =pod
73  
74 =head1 NAME
75  
76 Fey::Role::SQL::HasOrderByClause - A role for queries which can include a ORDER BY clause
77  
78 =head1 VERSION
79  
80 version 0.42
81  
82 =head1 SYNOPSIS
83  
84 use Moose 0.90;
85  
86 with 'Fey::Role::SQL::HasOrderByClause';
87  
88 =head1 DESCRIPTION
89  
90 Classes which do this role represent a query which can include a
91 C<ORDER BY> clause.
92  
93 =head1 METHODS
94  
95 This role provides the following methods:
96  
97 =head2 $query->order_by()
98  
99 See the L<Fey::SQL section on ORDER BY Clauses|Fey::SQL/ORDER BY
100 Clauses> for more details.
101  
102 =head2 $query->order_by_clause()
103  
104 Returns the C<ORDER BY> clause portion of the SQL statement as a
105 string.
106  
107 =head1 BUGS
108  
109 See L<Fey> for details on how to report bugs.
110  
111 =head1 AUTHOR
112  
113 Dave Rolsky <autarch@urth.org>
114  
115 =head1 COPYRIGHT AND LICENSE
116  
117 This software is Copyright (c) 2011 - 2015 by Dave Rolsky.
118  
119 This is free software, licensed under:
120  
121 The Artistic License 2.0 (GPL Compatible)
122  
123 =cut
« Fey/FK.pm ↑ Summary Fey/Role/SetOperation.pm »