JsonSQL/Query/Query.pm

filter: Statementstmt 96.4% 27 / 28 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 95.0% 38 / 40 CC 3 SCAR 4.1
CC
3
Cov
94%
new
2.0
quote_identifier
2.0
BEGIN
1.0
CRAP 1.5
« JsonSQL/Schemas/Schema.pm ↑ Summary JsonSQL/Error.pm »
1 # ABSTRACT: JSON query base class. Provides the quote_identifier method for escaping table and column identifiers.
2  
3  
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 package JsonSQL::Query::Query;
9  
10 2 our $VERSION = '0.4'; # VERSION
11  
12 2 ▶use JsonSQL::Validator;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15  
16 sub new {
17 11 ▶ my ( $class, $query_rulesets, $json_schema ) = @_;
Subroutine new: called CC=2 SCAR=7.1
Pod documented
18
19 ## DB specific values can be used in the future, but for now we are setting this to a common default.
20 11 my $self = {
21 _quoteChar => "'"
22 };
23
24 # Get a JsonSQL::Validator object with the provided $json_schema and $query_rulesets.
25 11 my $validator = JsonSQL::Validator->new($json_schema, $query_rulesets);
26 11 ▶ if ( eval { $validator->is_error } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { $validator->is_error } }) 0 11 11
27 0 return $validator;
28 }
29
30 # Save a reference to the JsonSQL::Validator for future processing of whitelisting rule sets.
31 11 $self->{_validator} = $validator;
32
33 11 bless $self, $class;
34 11 return $self;
35 }
36  
37  
38 sub quote_identifier {
39 45 ▶ my ( $self, $identifier ) = @_;
Subroutine quote_identifier: called CC=2 SCAR=6.9
Pod documented
40
41 ## This was taken and modified from Perl's DBI class.
42 45 my $quote = $self->{_quoteChar};
43 45 ▶ if ( defined $identifier ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $identifier) 44 1 45
44 44 $identifier =~ s/$quote/$quote$quote/g;
45 44 $identifier = qq($quote$identifier$quote);
46 }
47
48 45 return $identifier;
49 }
50  
51  
52 2 1;
53  
54 __END__
55  
56 =pod
57  
58 =encoding UTF-8
59  
60 =head1 NAME
61  
62 JsonSQL::Query::Query - JSON query base class. Provides the quote_identifier method for escaping table and column identifiers.
63  
64 =head1 VERSION
65  
66 version 0.4
67  
68 =head1 SYNOPSIS
69  
70 This is a base module used to construct JsonSQL::Query modules. It is not meant to be instantiated directly.
71 Instead have a look at,
72  
73 =over
74  
75 =item * L<JsonSQL::Query::Select>
76  
77 =item * L<JsonSQL::Query::Insert>
78  
79 =back
80  
81 You can also create your own subclass...
82  
83 =head1 METHODS
84  
85 =head2 Constructor new($query_rulesets, $json_schema) -> JsonSQL::Query::Query
86  
87 Creates a JsonSQL::Validator object using the supplied $query_rulesets and $json_schema and stores a reference to use for future
88 validation and whitelist checking purposes. See L<JsonSQL::Validator> for more information.
89  
90 $query_rulesets => The whitelist rule sets to be associated with this JsonSQL::Query object.
91 $json_schema => The name of the JSON schema to use for validation of the query.
92  
93 =head2 ObjectMethod quote_identifier($identifier) -> quoted $identifier
94  
95 Since table and column identifiers cannot be parameterized by most databases they have to be quoted. This method
96 is used during SQL query construction to quote non-parameterized identifiers.
97  
98 $identifier => The identifier string to quote.
99  
100 Ex:
101 Column1 => 'Column1'
102 Co'lumn1 => 'Co''lumn1'
103  
104 =head1 AUTHOR
105  
106 Chris Hoefler <bhoefler@draper.com>
107  
108 =head1 COPYRIGHT AND LICENSE
109  
110 This software is copyright (c) 2017 by Chris Hoefler.
111  
112 This is free software; you can redistribute it and/or modify it under
113 the same terms as the Perl 5 programming language system itself.
114  
115 =cut
« JsonSQL/Schemas/Schema.pm ↑ Summary JsonSQL/Error.pm »