| 1 | # ABSTRACT: JsonSQL::Param::Condition object. This is a base class used to derive subclasses for parsing condition statements. | ||
| 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::Condition; | ||
| 10 | |||
| 11 | 1 | our $VERSION = '0.4'; # VERSION | |
| 12 | |||
| 13 | 1 | ▶ | use JsonSQL::Error; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | |||
| 15 | |||
| 16 | |||
| 17 | sub new { | ||
| 18 | 7 | ▶ | my ( $class, $conditionhashref ) = @_; |
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||
| 19 | |||
| 20 | ## The schema restricts to one condition operator per level of the hashref, so just grab the first key at this level to use as the operator. | ||
| 21 | 7 | my ( $op ) = keys %{ $conditionhashref }; | |
| 22 | 7 | my $self = { | |
| 23 | _op => $op | ||
| 24 | }; | ||
| 25 | |||
| 26 | 7 | bless $self, $class; | |
| 27 | 7 | return $self; | |
| 28 | } | ||
| 29 | |||
| 30 | |||
| 31 | sub get_cond { | ||
| 32 | 2 | ▶ | my ( $self, $queryObj ) = @_; |
|
Subroutine
get_cond: called CC=1 SCAR=0.0
Pod
documented
| |||
| 33 | |||
| 34 | 2 | my $condObj = $self->get_sql_obj($queryObj); | |
| 35 | 2 | my $sql = $condObj->as_sql; | |
| 36 | 2 | my @binds = $condObj->bind; | |
| 37 | |||
| 38 | ## SMELL: Another QueryMaker workaround. Doesn't quote right. | ||
| 39 | 2 | $sql =~ s/`//g; | |
| 40 | |||
| 41 | 2 | return ($sql, \@binds); | |
| 42 | } | ||
| 43 | |||
| 44 | |||
| 45 | 1 | 1; | |
| 46 | |||
| 47 | __END__ | ||
| 48 | |||
| 49 | =pod | ||
| 50 | |||
| 51 | =encoding UTF-8 | ||
| 52 | |||
| 53 | =head1 NAME | ||
| 54 | |||
| 55 | JsonSQL::Param::Condition - JsonSQL::Param::Condition object. This is a base class used to derive subclasses for parsing condition statements. | ||
| 56 | |||
| 57 | =head1 VERSION | ||
| 58 | |||
| 59 | version 0.4 | ||
| 60 | |||
| 61 | =head1 SYNOPSIS | ||
| 62 | |||
| 63 | This module constructs a Perl object representing the VALUES parameter of an SQL INSERT statement and has methods for | ||
| 64 | generating the appropriate SQL string and bind values for use with the L<DBI> module. | ||
| 65 | |||
| 66 | =head1 DESCRIPTION | ||
| 67 | |||
| 68 | =head3 Object properties: | ||
| 69 | |||
| 70 | =over | ||
| 71 | |||
| 72 | =item _op => The operator used to construct the condition | ||
| 73 | |||
| 74 | (ex: 'and', 'eq', or 'in'). | ||
| 75 | |||
| 76 | =back | ||
| 77 | |||
| 78 | =head3 Generated parameters: | ||
| 79 | |||
| 80 | =over | ||
| 81 | |||
| 82 | =item $sql => SQL string of the condition | ||
| 83 | |||
| 84 | =item $binds => Arrayref of bind values to use with the query. | ||
| 85 | |||
| 86 | =back | ||
| 87 | |||
| 88 | =head1 METHODS | ||
| 89 | |||
| 90 | =head2 Constructor new($conditionhashref) | ||
| 91 | |||
| 92 | Instantiates and returns a new JsonSQL::Param::Condition object. | ||
| 93 | |||
| 94 | $conditionhashref => A hashref of the condition statement keyed by the operator. | ||
| 95 | |||
| 96 | Returns a JsonSQL::Error object on failure. | ||
| 97 | |||
| 98 | =head2 ObjectMethod get_cond -> ( $sql, $binds ) | ||
| 99 | |||
| 100 | Generates the SQL statement represented by the object. Returns: | ||
| 101 | |||
| 102 | $sql => An SQL string of conditional parameters to use with a conditional clause (ex: WHERE or ON). | ||
| 103 | $binds => An arrayref of parameterized values to pass with the query. | ||
| 104 | |||
| 105 | =head1 AUTHOR | ||
| 106 | |||
| 107 | Chris Hoefler <bhoefler@draper.com> | ||
| 108 | |||
| 109 | =head1 COPYRIGHT AND LICENSE | ||
| 110 | |||
| 111 | This software is copyright (c) 2017 by Chris Hoefler. | ||
| 112 | |||
| 113 | This is free software; you can redistribute it and/or modify it under | ||
| 114 | the same terms as the Perl 5 programming language system itself. | ||
| 115 | |||
| 116 | =cut | ||