NAME

Query::Tags::To::AST - Build AST from Query

DESCRIPTION

The Query::Tags::To::AST package implements a Pegex::Receiver based on Pegex::Tree. It is invoked from the Pegex parser engine to build the syntax tree contained in a Query::Tags object. What follows is a list of all node types which appear in this syntax tree.

Query::Tags::To::AST::Query

This is the root object and represents the entire query. Each assertion in the query is a pair object.

new

my $query = Query::Tags::To::AST::Query->new(@pairs);

Create a new query from a list of assertions.

pairs

my @pairs = $query->pairs;

Return the list of assertions.

test

$query->test($x, \%opts) ? 'PASS' : 'FAIL'

Check if $x passes all assertions.

Query::Tags::To::AST::Pair

A key-value pair represents the assertion that the key should exist and the values should match.

new

my $pair = Query::Tags::To::AST::Pair->new($key, $value);

Create a new pair object.

key

my $key = $pair->key;

Return the key as a Perl string.

value

my $value = $pair->value;

Return the value (another Query::Tags::To::AST::* object).

test

$pair->test($x, \%opts) ? 'PASS' : 'FAIL'

Check if $x matches the pair. This means the following: if $x is a blessed object and it has a method named $key, then it is invoked and its return value tested against $value. Otherwise, if $x is a hashref, the $key is looked up and its value is used. Otherwise the test fails.

If $key is undefined, the default_key is looked up in the options hashref \%opts. See "test" in Query::Tags for an explanation of its behavior. If both $key and default_key are undefined, the match fails.

If $value is undef, then only existence of the method or the hash key is required and its value is ignored. If instead $value is (not blessed and) equal to the string ?, then the value behind $key is checked for truthiness.

Query::Tags::To::AST::String

Represents a string. This object has the stringification and string comparison operators overloaded.

new

my $string = Query::Tags::To::AST::String->new($s);

Create a new string object from a Perl scalar string.

value

my $s = $string->value;

Return the Perl scalar string.

test

$string->test($x) ? 'PASS' : 'FAIL'

Check if $x eq $s.

Query::Tags::To::AST::Regex

Represents a regex. This object stringifies to the regex pattern.

new

my $regex = Query::Tags::To::AST::Regex->new($re);

Create a new regex object from a Perl regex.

value

my $re = $regex->value;

Return the underlying Perl regex.

test

$regex->test($x) ? 'PASS' : 'FAIL'

Check if $x =~ m/$re/.

Query::Tags::To::AST::Junction

Represents a junction, a superposition of multiple values which compares to a single value using a given mode.

new

my $j = Query::Tags::To::AST::Junction->new($negate, $type, @values);

Create a new junction of $type (optionally negated if $negate is truthy) over the given @values.

negated

my $negated = $j->negated;

Whether the junction is negated.

type

my $type = $j->type;

Return the junction type as a string &, | or !.

values

my @values = $j->values;

Return the values in the junction (as Query::Tags::To::AST::* objects).

test

$j->test($x) ? 'PASS' : 'FAIL'

Check if $x matches the junction. The type & implements an all junction, | implements any and ! implements none. These modes govern how the results of testing $x against the @values are interpreted. If the junction is negated, then the result will be inverted after it was computed.