SQLEngine/Criteria/Compound.pm

filter: Statementstmt 61.9% 26 / 42 Branchbran 50.0% 5 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod 83.3% 5 / 6 totaltotal 62.6% 42 / 67 CC 8 SCAR 16.3
CC
8
Cov
60%
expr
12.0
sql_where
6.1
push_subs
2.0
CRAP 5.1
« SQLEngine/Record/Class.pm ↑ Summary SQLEngine/Criteria.pm »
1 package DBIx::SQLEngine::Criteria::Compound;
2  
3 8 @ISA = 'DBIx::SQLEngine::Criteria';
4  
5 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 ########################################################################
9  
10 95 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
11 95 my $package = shift;
12 95 bless [ @_ ], $package;
13 }
14  
15 ########################################################################
16  
17 95 ▶sub subs {
Subroutine subs: called CC=1 SCAR=0.0
Pod documented
18 95 my $crit = shift;
19 95 @$crit
20 }
21  
22 0 ▶sub push_subs {
Subroutine push_subs: not called CC=1 SCAR=6.9
Pod documented
23 0 my $crit = shift;
24 0 push @{ $crit->subs }, @_
25 }
26  
27 0 ▶sub unshift_subs {
Subroutine unshift_subs: not called CC=1 SCAR=6.9
Pod documented
28 0 my $crit = shift;
29 0 unshift @{ $crit->subs }, @_
30 }
31  
32 ########################################################################
33  
34 8 ▶use Class::MakeMethods (
Subroutine BEGIN: called CC=1 SCAR=0.0
35 8 'Template::Class:string' => 'sql_join',
36 8 );
37  
38 95 ▶sub sql_where {
Subroutine sql_where: called CC=6 SCAR=18.2
Pod documented
39 95 my $self = shift;
40 95 my (@clauses, @params);
41 95 foreach my $sub ( $self->subs ) {
42 97 my ($sql, @v_params) = $sub->sql_where( @_ );
43 97 ▶ next if ( ! length $sql );
Branch: 1 branch
BranchTrueFalseTotal
unless length $sql 0 97 97
44 97 push @clauses, $sql;
45 97 push @params, @v_params;
46 }
47 95 ▶ return unless scalar @clauses;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @clauses 0 95 95
48 95 ▶ return ($clauses[0], @params) if ( scalar @clauses == 1 );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @clauses == 1 93 2 95
49 2 ▶ my $joiner = $self->sql_join or Carp::confess "Class does not have a joiner";
Branch: 1 branch
BranchTrueFalseTotal
my $joiner = $self->sql_join or Carp::confess("Class does not have a joiner") 2 0 2
50 2 return ( '( ' . join( " $joiner ", @clauses ) . ' )', @params );
51 }
52  
53 ########################################################################
54  
55 0 ▶sub expr {
Subroutine expr: not called CC=3 SCAR=24.8
Pod undocumented
56 0 my $self = shift;
57 0 my %exprs;
58 0 foreach my $sub ( $self->subs ) {
59 0 ▶ if ( $sub->expr =~ /ARRAY/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub->expr =~ /ARRAY/) { } 0 0 0
60 map {
61 0 $exprs{ $_ } = 1;
62 0 } @{$sub->expr};
63  
64 } else {
65 0 $exprs{ $sub->expr } = 1;
66 }
67 }
68 0 my @exprs = keys %exprs;
69 0 return \@exprs;
70 }
71  
72 8 1;
73  
74 ########################################################################
75  
76 =head1 NAME
77  
78 DBIx::SQLEngine::Criteria::Compound - Superclass for And and Or
79  
80 =head1 SYNOPSIS
81  
82 my $crit = DBIx::SQLEngine::Criteria::CompoundSubclass->new( $crit, ... );
83  
84  
85 =head1 DESCRIPTION
86  
87 DBIx::SQLEngine::Criteria::Compound objects are built around an array of other criteria.
88  
89  
90 =head1 REFERENCE
91  
92 =head2 Constructor
93  
94 =over 4
95  
96 =item new ( @criteria ) : $compound
97  
98 Constructor.
99  
100 =back
101  
102 =cut
103  
104 =head2 Content Access
105  
106 =over 4
107  
108 =item subs()
109  
110 $criteria->subs() : @criteria
111  
112 Returns all of the contained criteria.
113  
114 =item push_subs()
115  
116 $criteria->push_subs ( @criteria )
117  
118 =item unshift_subs()
119  
120 $criteria->unshift_subs ( @criteria )
121  
122 =back
123  
124  
125 =head2 SQL Where Generation
126  
127 =over 4
128  
129 =item sql_where()
130  
131 $criteria->sql_where() : $sql, @params
132  
133 Generates SQL criteria expression.
134  
135 =back
136  
137  
138 =head1 SEE ALSO
139  
140 See L<DBIx::SQLEngine::Criteria> and L<DBIx::SQLEngine::Criteria::Comparison>
141 for more information on using these objects.
142  
143 See L<DBIx::SQLEngine> for the overall interface and developer documentation.
144  
145 See L<DBIx::SQLEngine::Docs::ReadMe> for general information about
146 this distribution, including installation and license information.
147  
148 =cut
« SQLEngine/Record/Class.pm ↑ Summary SQLEngine/Criteria.pm »