DBIx::MyParsePP::Query - Query produced by DBIx::MyParsePP
use DBIx::MyParsePP; my $parser = DBIx::MyParsePP->new(); my $query = $parser->parse("SELECT 1"); if (not defined $query->root()) { print "Error at pos ".$query->pos()", line ".$pos->line()."\n"; } else { print "Query was ".$query->toString(); }
getLexer() returns the DBIx::MyParsePP::Lexer object for the string
getLexer()
getRoot() returns a DBIx::MYParsePP::Rule object representing the root of the parse tree
getRoot()
toString() walks the parse tree reconstructs the query using the individual tokens.
toString()
tokens() and getTokens() returns a reference to an array containing all tokens parsed as DBIx::MyParsePP::Token objects. If the parsing failed, the list contains all tokens up to the failure point.
tokens()
getTokens()
On error, getRoot() will return undef. You can call the following methods to determine the error:
undef
getExpected() returns a list of tokens the parser expected to find, whereas getActual() returns the actual token name that was encountered which caused the error. Please note that getActual() returns a DBIx::MyParsePP::Token object, whereas getExpected() returns a list of strings, containing just the token types.
getExpected()
getActual()
getLine() returns the line number where the error occured. getPos() returns the character position where the error occured, counting from the beginning of the string, not the begining of the line.
getLine()
getPos()
getTokens() can be used to reconstruct the query as it was up to the failure point.
getSelectItems(), getFrom(), getWhere(), getGroupBy(), getOrderBy(), getHaving() return the respective parts of the parse tree as a DBIx::MyParsePP::Rule object. Depending on the query, the part of the tree that is being returned may look differently, e.g. getFrom() will return widely different things depending on how many tables are in the FROM clause, whether there are joins or subqueries. You can then use shrink() and extract() on the return value to further narrow down on the part of the query you are interested in.
getSelectItems()
getFrom()
getWhere()
getGroupBy()
getOrderBy()
getHaving()
FROM
shrink()
extract()
To install DBIx::MyParsePP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::MyParsePP
CPAN shell
perl -MCPAN -e shell install DBIx::MyParsePP
For more information on module installation, please visit the detailed CPAN module installation guide.