| 1 | # ABSTRACT: JsonSQL::Param::Conditions::LogicCondition object. Subclass for parsing logic conditions (ex: 'and', 'or', etc). | ||||||||||
| 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::Conditions::LogicCondition; | ||||||||||
| 10 | |||||||||||
| 11 | 1 | our $VERSION = '0.4'; # VERSION | |||||||||
| 12 | |||||||||||
| 13 | 1 | ▶ | use base qw( JsonSQL::Param::Condition ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 1 | ▶ | use SQL::QueryMaker qw( sql_and sql_or ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | #use Data::Dumper; | ||||||||||
| 17 | |||||||||||
| 18 | 1 | ▶ | use JsonSQL::Error; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | ## Define the SQL::QueryMaker methods used for building up SQL condition statements. | ||||||||||
| 22 | 1 | my %dispatch = ( | |||||||||
| 23 | 'and' => \&sql_and, | ||||||||||
| 24 | 'or' => \&sql_or, | ||||||||||
| 25 | ); | ||||||||||
| 26 | |||||||||||
| 27 | |||||||||||
| 28 | |||||||||||
| 29 | sub new { | ||||||||||
| 30 | 2 | ▶ | my ( $class, $conditionhashref, $queryObj, $default_table_rules ) = @_; | ||||||||
|
Subroutine
new: called CC=4 SCAR=14.9
Pod
documented
| |||||||||||
| 31 | |||||||||||
| 32 | 2 | my $self = $class->SUPER::new($conditionhashref); | |||||||||
| 33 | 2 | my @condition_errors; | |||||||||
| 34 | |||||||||||
| 35 | 2 | for my $arghash (@{ $conditionhashref->{$self->{_op}} }) { | |||||||||
| 36 | 5 | my $argCondition = JsonSQL::Param::ConditionDispatcher->parse($arghash, $queryObj, $default_table_rules); | |||||||||
| 37 | 5 | ▶ | if ( eval { $argCondition->is_error } ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 0 | push(@condition_errors, "Error parsing logic condition argument: $argCondition->{message}"); | |||||||||
| 39 | } else { | ||||||||||
| 40 | 5 | push(@{ $self->{_args} }, $argCondition); | |||||||||
| 41 | } | ||||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 2 | ▶ | if ( @condition_errors ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 0 | my $err = "Error(s) constructing JsonSQL Condition object: \n\t"; | |||||||||
| 46 | 0 | $err .= join("\n\t", @condition_errors); | |||||||||
| 47 | 0 | return JsonSQL::Error->new("jsonsql_logiccondition", $err); | |||||||||
| 48 | } else { | ||||||||||
| 49 | 2 | return $self; | |||||||||
| 50 | } | ||||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | |||||||||||
| 54 | sub get_sql_obj { | ||||||||||
| 55 | 2 | ▶ | my ( $self, $queryObj ) = @_; | ||||||||
|
Subroutine
get_sql_obj: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 56 | |||||||||||
| 57 | 2 | my @cond_args = map { $_->get_sql_obj($queryObj) } @{ $self->{_args} }; | |||||||||
| 58 | |||||||||||
| 59 | 2 | ▶ | if (exists $dispatch{$self->{_op}}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 2 | return $dispatch{$self->{_op}}->(\@cond_args); | |||||||||
| 61 | } | ||||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | |||||||||||
| 65 | 1 | 1; | |||||||||
| 66 | |||||||||||
| 67 | __END__ | ||||||||||
| 68 | |||||||||||
| 69 | =pod | ||||||||||
| 70 | |||||||||||
| 71 | =encoding UTF-8 | ||||||||||
| 72 | |||||||||||
| 73 | =head1 NAME | ||||||||||
| 74 | |||||||||||
| 75 | JsonSQL::Param::Conditions::LogicCondition - JsonSQL::Param::Conditions::LogicCondition object. Subclass for parsing logic conditions (ex: 'and', 'or', etc). | ||||||||||
| 76 | |||||||||||
| 77 | =head1 VERSION | ||||||||||
| 78 | |||||||||||
| 79 | version 0.4 | ||||||||||
| 80 | |||||||||||
| 81 | =head1 SYNOPSIS | ||||||||||
| 82 | |||||||||||
| 83 | This module constructs a Perl object representing the VALUES parameter of an SQL INSERT statement and has methods for | ||||||||||
| 84 | generating the appropriate SQL string and bind values for use with the L<DBI> module. | ||||||||||
| 85 | |||||||||||
| 86 | =head1 DESCRIPTION | ||||||||||
| 87 | |||||||||||
| 88 | =head3 Object properties: | ||||||||||
| 89 | |||||||||||
| 90 | =over | ||||||||||
| 91 | |||||||||||
| 92 | =item _args => Array of L<JsonSQL::Param::Condition> objects to use as parameters. | ||||||||||
| 93 | |||||||||||
| 94 | =back | ||||||||||
| 95 | |||||||||||
| 96 | =head3 Generated parameters: | ||||||||||
| 97 | |||||||||||
| 98 | =over | ||||||||||
| 99 | |||||||||||
| 100 | =item $logicparameter => L<SQL::QueryMaker> object. | ||||||||||
| 101 | |||||||||||
| 102 | =back | ||||||||||
| 103 | |||||||||||
| 104 | =head1 METHODS | ||||||||||
| 105 | |||||||||||
| 106 | =head2 Constructor new($conditionhashref, $queryObj, $default_table_rules) | ||||||||||
| 107 | |||||||||||
| 108 | Instantiates and returns a new JsonSQL::Param::Conditions::LogicCondition object. | ||||||||||
| 109 | |||||||||||
| 110 | $conditionhashref => A hashref of the condition statement keyed by the operator. | ||||||||||
| 111 | $queryObj => A reference to the JsonSQL::Query object that will own this object. | ||||||||||
| 112 | $default_table_rules => The default whitelist table rules to use to validate access when the table params | ||||||||||
| 113 | are not provided to the field object. Usually, these are acquired from the table params | ||||||||||
| 114 | of another object (ex: the FROM clause of a SELECT statement). | ||||||||||
| 115 | |||||||||||
| 116 | Returns a JsonSQL::Error object on failure. | ||||||||||
| 117 | |||||||||||
| 118 | =head2 ObjectMethod get_sql_obj -> $logicparameter | ||||||||||
| 119 | |||||||||||
| 120 | Generates parameters represented by the object for the SQL statement. Returns: | ||||||||||
| 121 | |||||||||||
| 122 | $logicparameter => The logic condition to append to the WHERE clause. Constructed by calling the | ||||||||||
| 123 | L<SQL::QueryMaker> function defined by the dispatcher with the \@cond_args parameter. | ||||||||||
| 124 | |||||||||||
| 125 | =head1 AUTHOR | ||||||||||
| 126 | |||||||||||
| 127 | Chris Hoefler <bhoefler@draper.com> | ||||||||||
| 128 | |||||||||||
| 129 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 130 | |||||||||||
| 131 | This software is copyright (c) 2017 by Chris Hoefler. | ||||||||||
| 132 | |||||||||||
| 133 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 134 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 135 | |||||||||||
| 136 | =cut | ||||||||||