| DBIx-SQLEngine documentation | Contained in the DBIx-SQLEngine distribution. |
DBIx::SQLEngine::Criteria::Compound - Superclass for And and Or
my $crit = DBIx::SQLEngine::Criteria::CompoundSubclass->new( $crit, ... );
DBIx::SQLEngine::Criteria::Compound objects are built around an array of other criteria.
Constructor.
$criteria->subs() : @criteria
Returns all of the contained criteria.
$criteria->push_subs ( @criteria )
$criteria->unshift_subs ( @criteria )
$criteria->sql_where() : $sql, @params
Generates SQL criteria expression.
See DBIx::SQLEngine::Criteria and DBIx::SQLEngine::Criteria::Comparison for more information on using these objects.
See DBIx::SQLEngine for the overall interface and developer documentation.
See DBIx::SQLEngine::Docs::ReadMe for general information about this distribution, including installation and license information.
| DBIx-SQLEngine documentation | Contained in the DBIx-SQLEngine distribution. |
package DBIx::SQLEngine::Criteria::Compound; @ISA = 'DBIx::SQLEngine::Criteria'; use strict; use Carp; ######################################################################## sub new { my $package = shift; bless [ @_ ], $package; } ######################################################################## sub subs { my $crit = shift; @$crit } sub push_subs { my $crit = shift; push @{ $crit->subs }, @_ } sub unshift_subs { my $crit = shift; unshift @{ $crit->subs }, @_ } ######################################################################## use Class::MakeMethods ( 'Template::Class:string' => 'sql_join', ); sub sql_where { my $self = shift; my (@clauses, @params); foreach my $sub ( $self->subs ) { my ($sql, @v_params) = $sub->sql_where( @_ ); next if ( ! length $sql ); push @clauses, $sql; push @params, @v_params; } return unless scalar @clauses; return ($clauses[0], @params) if ( scalar @clauses == 1 ); my $joiner = $self->sql_join or Carp::confess "Class does not have a joiner"; return ( '( ' . join( " $joiner ", @clauses ) . ' )', @params ); } ######################################################################## sub expr { my $self = shift; my %exprs; foreach my $sub ( $self->subs ) { if ( $sub->expr =~ /ARRAY/ ) { map { $exprs{ $_ } = 1; } @{$sub->expr}; } else { $exprs{ $sub->expr } = 1; } } my @exprs = keys %exprs; return \@exprs; } 1; ########################################################################