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

NAME

 Class::ReluctantORM::SQL::Function - Represent a SQL function, aggregator, stored proc, or operator

SYNOPSIS

 use Class::ReluctantORM::SQL::Aliases;

 # Explicit lookup....
 my $eq = Function->by_name('='); # not case senstive
 my $min_arity = $eq->min_inputs; # 2 for '='


 # Usually used implicitly....
 # This automatically looks up the '=' function by name
 my $crit = Criterion->new('=', $column, $param);
 my $crit2 = Criterion->new($func, $column, $param);

 # Looks up '=' implicitly
 my $fc1 = FunctionCall->new('=', $column, $param);
 my $fc2 = FunctionCall->new($func, $column, $param);

 # Register new custom functions
 Function->register(
  name => 'froobulate',
  min_inputs => 2,
  max_inputs => 43,
  is_associative => 1,
  is_cummutative => 1,
 );

 # Now...
 my $crit = Criterion->new('froobulate', $column, $param);

 # Note: your driver must know how to render froobulate!

 # List functions
 my @funcs = Function->list_all_functions();
 my @funcs = Function->list_default_functions();
 my @funcs = Function->list_aggregate_functions();

DESCRIPTION

Registry for functions, operators, and stored procedures, so that they may be represented in an abstract SQL tree.

Each individual function is treated as a singleton by name; so if you request (explicitly or implicitly) the '=' operator two different times, you will get the same object both times.

Default Function Kit

A fair number of functions are pre-registered, including = < > AND OR NOT. You can get the complete list by calling Function->list_default_functions().

A Function is Not a Function Call

A Function object represents _which_ function is being referred to. To actually call a function in an abstract SQL tree, create a FunctionCall object.

INSTANCE RETRIEVAL ("CONSTRUCTOR")

$f = Function->by_name('name');

Searches for a function with the name given, and returns it. Throws an exception if no such function has been registered.

The search is case-insensitive.

$bool = Function->is_registered('name');

Returns true if the function name is registered.

OTHER CLASS METHODS

$f = Function->register(%options);

Registers a new Function. After this, you can explicitly or implicitly refer to the function by name.

Options:

name

Required string, may be symbols. Must be unique - no other registered Function may have the same name.

min_inputs

Required positive integer. Minimum number of arguments the function takes.

max_inputs

Optional positive integer. If not provided, Function is assumed to have no limit.

is_aggregate

Optional boolean, default false. If true, marks this function as an aggregrate function.

is_associative

Optional boolean, default false. If true, indicates CRO can re-group multiple invocations of this function. So, (1+2)+3 = 1+(2+3).

is_commutative

Optional boolean, default false. If true, indicates CRO can re-order arguments of this function. So, 1+2 = 2+1.

@funcs = Function->list_all_functions();

Returns an array of all registered functions.

@funcs = Function->list_default_functions();

Returns an array of all functions that are provided by default, and guarenteed to be renderable by all drivers.

@funcs = Function->list_aggregate_functions();

Returns an array of all aggregate functions.

INSTANCE METHODS

$str = $f->name()

Returns the name of the Function. Always available and always unique.

$int = $f->min_inputs()

Returns the minimum number of inputs the function accepts. Always available.

$int = $f->max_inputs()

Returns the maximum number of inputs the function accepts. May be undef, in which case the function has no upper limit on the number of inputs. May also be zero, as for NOW().

$bool = $f->is_default()

Returns true if the function is part of the default kit, which all drivers are required to be able to render. Returns false if the Function was registered by you.

$bool = $f->is_aggregate()

Returns true if the function is an aggregate function, like COUNT or MAX. These functions may only be used in output column expressions, and alter the semantics of the query.

$same = $func->clone();

Sine each function is a singleton, it doesn't make sense to clone them. This method thus returns the original, and is provided for consistency with other SQL objects.