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