SQLEngine/Criteria/Comparison.pm

filter: Statementstmt 84.0% 21 / 25 Branchbran 50.0% 6 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 77.2% 34 / 44 CC 7 SCAR 19.2
CC
7
Cov
73%
sql_where
10.1
BEGIN
1.0
new
1.0
CRAP 6.8
« SQLEngine/Driver/Trait/NoSequences.pm ↑ Summary SQLEngine/Driver/SQLite.pm »
1 =head1 NAME
2  
3 DBIx::SQLEngine::Criteria::Comparison - Superclass for comparisons
4  
5 =head1 SYNOPSIS
6  
7 my $crit = DBIx::SQLEngine::Criteria::ComparisonSubclass->new( $key, $value );
8  
9  
10 =head1 DESCRIPTION
11  
12 DBIx::SQLEngine::Criteria::Comparison objects provide a structured representation of certain simple kinds of SQL criteria clauses, those of the form C<column_or_expression comparison_operator comparison_value>.
13  
14 Each Criteria::Comparison object is implemented in the form of blessed arrayref, with two items in the array. The first is the column name (or SQL expression) to be compared against, and the second is the comparison value. The type of comparison operator to use is indicated by which subclass of Criteria::Comparison the object is blessed into.
15  
16 The comparison value is assumed by default to be a literal string or numeric value, and uses parameter substitution to avoid having to deal with quoting. If you actually want to compare against another column or expression, pass a reference to the column name or expression string. For example, to select records where C<first_name = last_name>, you could use:
17  
18 DBIx::SQLEngine::Criteria::Equality->('first_name', \'last_name');
19  
20 =cut
21  
22 package DBIx::SQLEngine::Criteria::Comparison;
23 12 @ISA = 'DBIx::SQLEngine::Criteria';
24 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 ########################################################################
27  
28 =head1 REFERENCE
29  
30 =head2 Constructor
31  
32 =over 4
33  
34 =item new ( $key, $value ) : $Comparison
35  
36 Constructor.
37  
38 =back
39  
40 =cut
41  
42 47 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
43 47 my $package = shift;
44 47 bless [ @_ ], $package;
45 }
46  
47  
48 ########################################################################
49  
50 =head2 Content Access
51  
52 =over 4
53  
54 =item expr () : $fieldname
55  
56 =item expr ( $fieldname )
57  
58 Accessor.
59  
60 =item compv () : $comparsion_value
61  
62 =item compv ( $comparsion_value )
63  
64 Accessor.
65  
66 =back
67  
68 =cut
69  
70 12 ▶use Class::MakeMethods (
Subroutine BEGIN: called CC=1 SCAR=0.0
71 12 'Standard::Array:scalar' => 'expr',
72 'Standard::Array:scalar' => 'compv',
73 12 );
74  
75 ########################################################################
76  
77 =head2 Evaluation
78  
79 =over 4
80  
81 =item sql_comparator () : $operator
82  
83 Returns operator associated with this criteria, such as "=" or "like".
84  
85 =item sql_where () : $sql_where_expression
86  
87 Generates SQL criteria expression.
88  
89 Automatically converts "= NULL" to "IS NULL".
90  
91 =back
92  
93 =cut
94  
95 12 ▶use Class::MakeMethods (
Subroutine BEGIN: called CC=1 SCAR=0.0
96 12 'Template::Class:string' => 'sql_comparator',
97 12 );
98  
99 47 ▶sub sql_where {
Subroutine sql_where: called CC=7 SCAR=23.2
Pod documented
100 47 my $self = shift;
101 47 my $expr = $self->expr;
102 47 ▶ ( length $expr ) or Carp::confess("Expression is missing or empty");
Branch: 1 branch
BranchTrueFalseTotal
length $expr or Carp::confess("Expression is missing or empty") 47 0 47
103 47 my $compv = $self->compv;
104 # 2002-11-02 Patch from Michael Kroell, University of Innsbruck
105 #( defined $compv ) or Carp::confess("Comparison value is missing or empty");
106 47 my $cmp = $self->sql_comparator;
107 47 ▶ ( length $cmp ) or Carp::confess("sql_comparator is missing or empty");
Branch: 1 branch
BranchTrueFalseTotal
length $cmp or Carp::confess("sql_comparator is missing or empty") 47 0 47
108
109 # 2002-11-02 Based on patch from Michael Kroll, University of Innsbruck
110 47 ▶ if ( ! defined($compv) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $compv) { } 0 47 47
elsif (not ref $compv) { } 39 8 47
elsif (ref $compv eq 'SCALAR') { } 8 0 8
111 0 ▶ if ( $cmp eq '=' ) { $cmp = 'IS' }
Branch: 1 branch
BranchTrueFalseTotal
if ($cmp eq "=") 0 0 0
112 0 join(' ', $expr, $cmp, 'NULL' );
113 } elsif ( ! ref($compv) ) {
114 39 join(' ', $expr, $cmp, '?' ), $compv;
115 } elsif ( ref($compv) eq 'SCALAR' ) {
116 8 join(' ', $expr, $cmp, $$compv );
117 } else {
118 0 Carp::confess("Can't use '$compv' as a comparison value");
119 }
120 }
121  
122 ########################################################################
123  
124  
125 =head1 SEE ALSO
126  
127 See L<DBIx::SQLEngine::Criteria> and L<DBIx::SQLEngine::Criteria::Comparison>
128 for more information on using these objects.
129  
130 See L<DBIx::SQLEngine> for the overall interface and developer documentation.
131  
132 See L<DBIx::SQLEngine::Docs::ReadMe> for general information about
133 this distribution, including installation and license information.
134  
135 =cut
« SQLEngine/Driver/Trait/NoSequences.pm ↑ Summary SQLEngine/Driver/SQLite.pm »