NAME
Language::Expr::Compiler::Perl - Compile Language::Expr expression to Perl
VERSION
version 0.10
SYNOPSIS
use Language::Expr::Compiler::Perl;
my $plc = Language::Expr::Compiler::Perl->new;
print $plc->perl('1 ^^ 2'); # prints '1 xor 2'
DESCRIPTION
Compiles Language::Expr expression to Perl code. Some notes:
Emitted Perl code version
Emitted Perl code requires Perl 5.10 (it uses 5.10's "//" defined-or operator) and also the boolean module (it uses 'true' and 'false' objects).
Perliness
The emitted Perl code will follow Perl's notion of true and false, e.g. the expression '"" || "0" || 2' will result to 2 since Perl thinks that "" and "0" are false. It is also weakly typed like Perl, i.e. allows '1 + "2"' to become 3.
Currently strings are rudimentary escaped.
Data dumping modules can't be used currently due to segfaults (at least in 5.10.1).
Variables by default simply use Perl variables.
E.g. $a becomes $a, and so on. Be careful not to make variables which are invalid in Perl, e.g. $.. or ${foo/bar} (but ${foo::bar} is okay because it translates to $foo::bar).
You can subclass and override rule_var() if you want to provide your own variables.
Functions by default simply use Perl functions.
Unless those specified in func_mapping. For example, if $compiler->func_mapping->{foo} = "Foo::do_it", then the expression 'foo(1)' will be compiled into 'Foo::do_it(1)'.
ATTRIBUTES
hook_var
Can be set to a coderef that will be called during parsing whenever variable is encountered. The coderef is expected to return Perl code to handle the variable. By default, if this attribute is not set, variable in expression is returned as is (e.g. '$foo' becomes '$foo' in Perl), which means some will result in error (e.g. '${name that contains some symbols that makes it invalid Perl)').
METHODS
perl($expr) => $perl_code
Convert Language::Expr expression into Perl code. Dies if there is syntax error in expression.
AUTHOR
Steven Haryanto <stevenharyanto@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2010 by Steven Haryanto.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.