NAME

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

VERSION

This document describes version 0.22 of module Language::Expr::Compiler::PHP (in distribution Language-Expr), released on 2014-04-28.

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.

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Language-Expr.

SOURCE

Source repository is at https://github.com/sharyanto/perl-Language-Expr.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Language-Expr

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

AUTHOR

Steven Haryanto <stevenharyanto@gmail.com>

COPYRIGHT AND LICENSE

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