Tree::Predicate - a balanced, splittable tree for SQL predicates
Tree::Predicate allows the composition of a tree of SQL predicates that can then be "split" into UNION-able predicats that do not contain an OR.
use Tree::Predicate qw(:logical); my $left_branch = OR('a', 'b'); my $right_branch = OR('c', 'd'); my $tree = AND($left_branch, $right_branch); print $tree->as_string; # ((a OR b) AND (c OR d)) my @trees = $tree->split; # four trees # (a AND c) # (a AND d) # (b AND c) # (b AND d) $tree->negate; print $tree->as_string; # ((NOT(a) AND NOT(b)) OR (NOT(c) AND NOT(d)))
AND/OR/NOT may be individually imported, or they may be collectively imported with :logical.
expresses the tree as a string suitable for including in SQL
negates the tree
returns a list (or reference) of the tree's operands, for whatever you might want that
returns a list of subtrees that can be used in a UNION statement to produce a logically equivalent query.
dies if number of children exceeds SPLIT_LIMIT
constructors for trees
<dmarshal at yahoo-inc.com>
Please report any bugs or feature requests to
bug-tree-predicate at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Tree-Predicate. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
You can also look for information at:
Copyright 2009 Yahoo! Inc., all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.