Imager::Expr(3pm) | User Contributed Perl Documentation | Imager::Expr(3pm) |
Imager::Expr - implements expression parsing and compilation for the expression evaluation engine used by Imager::transform2()
my $code =
Imager::Expr->new({rpnexpr=>$someexpr})
or die "Cannot compile $someexpr:
",Imager::Expr::error();
This module is used internally by the Imager::transform2() function. You shouldn't have much need to use it directly, but you may want to extend it.
To create a new Imager::Expr object, call:
my %options; my $expr = Imager::Expr->new(\%options) or die Imager::Expr::error();
You will need to set an expression value and you may set any of the following:
A hashref defining extra constants for expression parsing. The names of the constants must be valid identifiers (/[^\W\d]\w*/) and the values must be valid numeric constants (that Perl recognizes in scalars).
Imager::Expr may define it's own constants (currently just pi.)
A reference to an array of variable names. These are allocated numeric registers starting from register zero.
By default you can define a "rpnexpr" key (which emulates RPN) or "expr" (an infix expression). It's also possible to write other expression parsers that will use other keys. Only one expression key should be defined.
The Imager::Expr::error() method is used to retrieve the error if the expression object cannot be created.
Imager::Expr provides only a few simple methods meant for external use:
if (Imager::Expr->type_registered('expr')) { # use infix expressions }
I'll write this one day.
Methods used by parsers:
It's supplied the following parameters:
Return an array ref of array refs containing opcodes and operands.
YourClassName->register_type('type code');
where type code is the parameter that will accept the expression.
Try to avoid doing your own optimization beyond literal folding - if we add some sort of jump, the existing optimizer will need to be rewritten, and any optimization you perform may well be broken too (well, your code generation will probably be broken anyway <sigh>).
Tony Cook <tonyc@cpan.org>, Arnar M. Hrafnkelsson
2023-01-11 | perl v5.36.0 |