JsonSQL/Param/Conditions/NullCondition.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 52 CC 3 SCAR 12.4
CC
3
Cov
0%
new
6.0
get_sql_obj
6.0
BEGIN
2.0
CRAP 3.5
1 # ABSTRACT: JsonSQL::Param::Conditions::NullCondition object. Subclass for parsing null conditions.
2  
3  
4  
5 use strict;
6 use warnings;
7 use 5.014;
8  
9 package JsonSQL::Param::Conditions::NullCondition;
10  
11 our $VERSION = '0.4'; # VERSION
12  
13 use base qw( JsonSQL::Param::Condition );
14  
15 use SQL::QueryMaker qw( sql_is_null sql_is_not_null );
16 #use Data::Dumper;
17  
18 use JsonSQL::Param::Field;
19 use JsonSQL::Error;
20  
21  
22 ## Define the SQL::QueryMaker methods used for building up SQL condition statements.
23 my %dispatch = (
24 'isnull' => \&sql_is_null,
25 'notnull' => \&sql_is_not_null
26 );
27  
28  
29  
30 sub new {
31 my ( $class, $conditionhashref, $queryObj, $default_table_rules ) = @_;
32
33 my $self = $class->SUPER::new($conditionhashref);
34
35 my $field = $conditionhashref->{$self->{_op}}->{field};
36 my $conditionField = JsonSQL::Param::Field->new($field, $queryObj, $default_table_rules);
37 if ( eval { $conditionField->is_error } ) {
38 return JsonSQL::Error->new("jsonsql_nullcondition", "Error using field $field in null condition: $conditionField->{message}");
39 } else {
40 $self->{_field} = $conditionField;
41 return $self;
42 }
43 }
44  
45  
46 sub get_sql_obj {
47 my ( $self, $queryObj ) = @_;
48
49 if (exists $dispatch{$self->{_op}}) {
50 my $field = $self->{_field}->get_field_param($queryObj);
51 return $dispatch{$self->{_op}}->($field);
52 }
53 }
54  
55  
56 1;
57  
58 __END__
59  
60 =pod
61  
62 =encoding UTF-8
63  
64 =head1 NAME
65  
66 JsonSQL::Param::Conditions::NullCondition - JsonSQL::Param::Conditions::NullCondition object. Subclass for parsing null conditions.
67  
68 =head1 VERSION
69  
70 version 0.4
71  
72 =head1 SYNOPSIS
73  
74 This module constructs a Perl object representing the VALUES parameter of an SQL INSERT statement and has methods for
75 generating the appropriate SQL string and bind values for use with the L<DBI> module.
76  
77 =head1 DESCRIPTION
78  
79 =head3 Object properties:
80  
81 =over
82  
83 =item _field => L<JsonSQL::Param::Field>
84  
85 =back
86  
87 =head3 Generated parameters:
88  
89 =over
90  
91 =item $nullparameter => L<SQL::QueryMaker> object.
92  
93 =back
94  
95 =head1 METHODS
96  
97 =head2 Constructor new($conditionhashref, $queryObj, $default_table_rules)
98  
99 Instantiates and returns a new JsonSQL::Param::Conditions::NullCondition object.
100  
101 $conditionhashref => A hashref of the condition statement keyed by the operator.
102 $queryObj => A reference to the JsonSQL::Query object that will own this object.
103 $default_table_rules => The default whitelist table rules to use to validate access when the table params
104 are not provided to the field object. Usually, these are acquired from the table params
105 of another object (ex: the FROM clause of a SELECT statement).
106  
107 Returns a JsonSQL::Error object on failure.
108  
109 =head2 ObjectMethod get_sql_obj -> $nullparameter
110  
111 Generates parameters represented by the object for the SQL statement. Returns:
112  
113 $nullparameter => The null condition to append to the WHERE clause. Constructed by calling the
114 L<SQL::QueryMaker> function defined by the dispatcher with the $field parameter.
115  
116 =head1 AUTHOR
117  
118 Chris Hoefler <bhoefler@draper.com>
119  
120 =head1 COPYRIGHT AND LICENSE
121  
122 This software is copyright (c) 2017 by Chris Hoefler.
123  
124 This is free software; you can redistribute it and/or modify it under
125 the same terms as the Perl 5 programming language system itself.
126  
127 =cut