The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Class::ReluctantORM::SQL::Expression::FunctionCall - Represent a function call

SYNOPSIS

  # Save yourself some typing
  use Class::ReluctantORM::SQL::Aliases;

  # This creates "REPLACE(mycol,'old','new')"
  my $fc0 = FunctionCall->new(
                              'replace',
                              Column->new(column =>'mycol',
                              'old',
                              'new',
                             );

  # Same thing
  my $fc0 = FunctionCall->new(
                              Function->by_name('replace'),
                              Column->new(column =>'mycol',
                              'old',
                              'new',
                             );

  # This creates '1=1'
  my $fc1 = FunctionCall->new('=', 1, 1);

  # This creates 'my_column = ?'
  my $fc2 = FunctionCall->new(
                             '=',
                             Column->new(column =>'my_column',
                             Param->new(),
                            );

  # Wrap $fc2 in NOT ( 'NOT my_column = ?' )
  my $fc3 = FunctionCall->new('NOT', $fc2);

  # Make '(1=1) AND (NOT (my_column = ?))'
  my $fc4 = FunctionCall->new('AND', $fc1, $fc3);

  # Dump a FunctionCall as a string (for diagnostics only - NOT RBMS safe)
  my $str = $fc->pretty_print();  # Verbose
  my $str = $fc->pretty_print(one_line => 1);

DESCRIPTION

Represents an actual call to a function, operator, or stored procedure. Contains a single Function, and zero or more Expressions that are used as arguments to the Function.

FunctionCalls are themselves Expressions, so they can be composed (nested).

CONSTRUCTORS

$fc = SQL::Expression::FunctionCall->new($func, $exp1, [$exp2, ...]);

$fc = SQL::Expression::FunctionCall->new($funcname, $exp1, [$exp2,...]);

Creates a new FunctionCall. The Function to be called must be specified, as well as all input expressions.

In the first form, the Function to be called is provided directly.

In the second form, the Function is specified by name, and a Function->by_name lookup is made on your behalf.

An exception will be thrown if the number of arguments does not match the operator's arity.

$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.

$clone = $fc->clone();

Makes a new FunctionCall. The arguments of the original are deeply cloned. The Function itself will be re-used, since each Function type is a singleton.

ACCESSORS

@exps = $fc->arguments();

Returns the input expressions of the function call.

@exps = $fc->child_expressions();

Returns the child nodes of this node (same as arguments()). Required by the Expression interface.

$bool = $arg->is_function_call();

All objects of this class return true. The class adds this method to Expression, making all other subclasses of it return false.

$bool = $fc->is_leaf_expression();

Returns true if the number of arguments to the function call are zero. Required by the Expression interface.

$func = $fc->function();

Returns the Function being referred to by the FunctionCall.

$str = $fc->pretty_print();

Renders a human-readable representation of the FunctionCall.