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

NAME

Tree::Predicate - a balanced, splittable tree for SQL predicates

VERSION

Version 0.03

SYNOPSIS

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)))

EXPORT

AND/OR/NOT may be individually imported, or they may be collectively imported with :logical.

FUNCTIONS

as_string

expresses the tree as a string suitable for including in SQL

negate

negates the tree

operands

returns a list (or reference) of the tree's operands, for whatever you might want that

split

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

AND/OR/NOT

constructors for trees

AUTHOR

David Marshall, <dmarshal at yahoo-inc.com>

BUGS

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.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Tree::Predicate

You can also look for information at:

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

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.