NAME
Class::ReluctantORM::SQL::Expression::Criterion - Represent WHERE and JOIN criteria
SYNOPSIS
# Save yourself some typing
use Class::ReluctantORM::SQL::Aliases;
# This creates an "always true" criteria
my $crit = Criterion->new_tautology();
# This creates '1=1'
my $crit1 = Criterion->new('=', 1, 1);
# This creates 'my_column = ?'
my $crit2 = Criterion->new(
'=',
Column->new(column =>'my_column',
Param->new(),
);
# Wrap $crit2 in NOT ( 'NOT my_column = ?' )
my $crit3 = Criterion->new('NOT', $crit2);
# Make '(1=1) AND (NOT (my_column = ?))'
my $crit4 = Criterion->new('AND', $crit1, $crit3);
# Make a where clause with this as its root
my $where = Where->new($crit4);
# Or AND it to an existing one
$where2->and($crit4);
# Dump a Criterion as a string (for diagnostics only - NOT RBMS safe)
my $str = $crit->pretty_print(); # Verbose
my $str = $crit->pretty_print(one_line => 1);
DESCRIPTION
Represents a boolean-return predicate call, as needed in JOIN criteria and WHERE clauses.
This is a specialized subclass of a FunctionCall.
CONSTRUCTORS
$crit = SQL::Expression::Criterion->new();
$crit = SQL::Expression::Criterion->new($op_name, $exp1, [$exp2, ...]);
$crit = SQL::Expression::Criterion->new($function, $exp1, [$exp2, ...]);
Creates a new criterion.
In the first form, returns an always true criterion.
In the second and third form, creates a new criterion using the specified operator and argument(s). An exception will be thrown if the number of arguments does not match the operator's arity.
$op is a string name of a Function. Case is ignored.
$expN is either a Class::ReluctantORM::SQL::Expression subclass, or a plain scalar, or undef. Scalars and undefs will be "autoboxed" into being Class::ReluctantORM::SQL::Expression::Literal objects, with undefs becoming NULLs.
$crit = SQL::Expression::Criterion->new_tautology();
Returns an 'always true' criterion.
ACCESSORS
@args = $crit->arguments();
Returns the arguments of the criterion.
@args = $crit->child_expressions();
Returns the child nodes of this node (same as arguments()). Required by the Expression interface.
$bool = $arg->is_criterion();
All objects of this class return true. The class adds this method to Expression, making all other subclasses of it return false.
$bool = $crit->is_leaf_expression();
Always returns false for this class. Required by the Expression interface.
$func = $crit->function();
Returns the Function that represents the operator.
$str = $crit->pretty_print();
Renders a human-readable representation of the Criterion.
$bool = $crit->is_equivalent($other_crit);
Returns true if the two criteria are certainly equivalent (does not check table or column aliases).
Returns false otherwise.
AUTHOR
Clinton Wolfe January 2009, January 2010