JsonSQL/Param/OrderBy.pm

filter: Statementstmt 42.1% 16 / 38 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod 100% 2 / 2 totaltotal 45.1% 23 / 51 CC 4 SCAR 21.6
CC
4
Cov
38%
new
20.0
get_ordering
2.0
BEGIN
1.0
CRAP 8.7
« JsonSQL/Param/Field.pm ↑ Summary JsonSQL/Param/Conditions/EnumCondition.pm »
1 # ABSTRACT: JsonSQL::Param::OrderBy object. Stores an array of JsonSQL::Param::Order objects to use for constructing JsonSQL::Query objects.
2  
3  
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 package JsonSQL::Param::OrderBy;
10  
11 1 our $VERSION = '0.4'; # VERSION
12  
13 1 ▶use JsonSQL::Param::Order;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use JsonSQL::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 #use Data::Dumper;
17  
18  
19  
20 sub new {
21 0 ▶ my ( $class, $orderarrayref, $queryObj, $default_table_rules ) = @_;
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
22
23 0 my $self = [];
24 0 my @orderby_errors;
25
26 0 for my $orderhashref ( @{ $orderarrayref } ) {
27 0 my $orderByObj = JsonSQL::Param::Order->new($orderhashref, $queryObj, $default_table_rules);
28 0 ▶ if ( eval { $orderByObj->is_error } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { $orderByObj->is_error } }) { } 0 0 0
29 0 push(@orderby_errors, $orderByObj->{message});
30 } else {
31 0 push (@{ $self }, $orderByObj);
32 }
33 }
34
35 0 ▶ if ( @orderby_errors ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@orderby_errors) { } 0 0 0
36 0 my $err = "Could not parse all order objects: \n\t";
37 0 $err .= join("\n\t", @orderby_errors);
38 0 return JsonSQL::Error->new("invalid_orderby", $err);
39 } else {
40 0 bless $self, $class;
41 0 return $self;
42 }
43 }
44  
45  
46 sub get_ordering {
47 0 ▶ my ( $self, $queryObj ) = @_;
Subroutine get_ordering: not called CC=1 SCAR=6.9
Pod documented
48
49 0 my @orderingArray = map { $_->get_orderby } @{ $self };
50
51 0 return \@orderingArray;
52 }
53  
54  
55 1 1;
56  
57 __END__
58  
59 =pod
60  
61 =encoding UTF-8
62  
63 =head1 NAME
64  
65 JsonSQL::Param::OrderBy - JsonSQL::Param::OrderBy object. Stores an array of JsonSQL::Param::Order objects to use for constructing JsonSQL::Query objects.
66  
67 =head1 VERSION
68  
69 version 0.4
70  
71 =head1 SYNOPSIS
72  
73 This module constructs a Perl object container of L<JsonSQL::Param::Order> objects.
74  
75 =head1 DESCRIPTION
76  
77 =head3 Object properties:
78  
79 =over
80  
81 =item Array of L<JsonSQL::Param::Order> objects.
82  
83 =back
84  
85 =head3 Generated parameters:
86  
87 =over
88  
89 =item $orderingArray => \@arrayref
90  
91 =back
92  
93 =head1 METHODS
94  
95 =head2 Constructor new($orderarrayref, $queryObj, $default_table_rules)
96  
97 Instantiates and returns a new JsonSQL::Param::OrderBy object, which is an array of L<JsonSQL::Param::Order> objects.
98  
99 $orderarrayref => An arrayref of order hashes used to construct the object.
100 $queryObj => A reference to the JsonSQL::Query object that will own this object.
101 $default_table_rules => The default whitelist table rules to use to validate access when the table params
102 are not provided to the field object. Usually, these are acquired from the table params
103 of another object (ex: the FROM clause of a SELECT statement).
104  
105 Returns a JsonSQL::Error object on failure.
106  
107 =head2 ObjectMethod get_ordering -> \@orderingArray
108  
109 Generates parameters represented by the object for the SQL statement. Returns:
110  
111 $orderingArray => Arrayref of ordering parameters to use for the query. Constructed from child L<JsonSQL::Param::Order> objects.
112  
113 =head1 AUTHOR
114  
115 Chris Hoefler <bhoefler@draper.com>
116  
117 =head1 COPYRIGHT AND LICENSE
118  
119 This software is copyright (c) 2017 by Chris Hoefler.
120  
121 This is free software; you can redistribute it and/or modify it under
122 the same terms as the Perl 5 programming language system itself.
123  
124 =cut
« JsonSQL/Param/Field.pm ↑ Summary JsonSQL/Param/Conditions/EnumCondition.pm »