++ed by:
TOBYINK

1 PAUSE user

Steven Haryanto

NAME

Language::Expr::Compiler::PHP - Compile Language::Expr expression to PHP

VERSION

version 0.21

SYNOPSIS

 use Language::Expr::Compiler::PHP;
 my $phpc = Language::Expr::Compiler::PHP->new;
 print $phpc->php('[1, 2, 3])'); # prints: array(1, 2, 3)

 # map Expr function to PHP function
 $phpc->func_mapping->{uc} = 'strtoupper';
 print $phpc->php(q{uc("party like it's ") . ceil(1998.9)}); # prints: strtoupper("party like it's " + ceil(1998.9)

DESCRIPTION

Compiles Language::Expr expression to PHP code. Some notes:

  • PHP version

    This compiler emits PHP 5.3 code (it uses lambda functions).

    Currently to test emitted JavaScript code, we use PHP command line interpreter as the PHP and PHP::Interpreter modules are still not up to par.

  • PHP-ness

    The emitted PHP code will follow PHP's weak typing, coercion rules, notions of true/false (which, fortunately, mimics closely that of Perl).

  • Variables by default simply use PHP variables.

    E.g. $a becomes $a, and so on. Be careful not to make variables which are invalid in PHP, e.g. $.. or ${foo/bar}.

    You can customize this behaviour by subclassing rule_var() or by providing a hook_var() (see documentation in Language::Expr::Compiler::Base).

  • Functions by default simply use PHP functions.

    foo() becomes foo(). Except those mentioned in func_mapping (e.g. uc() becomes strtoupper() if func_mapping->{uc} is 'strtoupper').

    You can customize this behaviour by subclassing rule_func() or by providing a hook_func() (see documentation in Language::Expr::Compiler::Base).

METHODS

php($expr) => $php_code

Convert Language::Expr expression into PHP code. Dies if there is syntax error in expression.

AUTHOR

Steven Haryanto <stevenharyanto@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 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.