Eval::TypeTiny::CodeAccumulator(3pm) | User Contributed Perl Documentation | Eval::TypeTiny::CodeAccumulator(3pm) |
Eval::TypeTiny::CodeAccumulator - alternative API for Eval::TypeTiny
my $make_adder = 'Eval::TypeTiny::CodeAccumulator'->new( description => 'adder', ); my $n = 40; my $varname = $make_adder->add_variable( '$addend' => \$n ); $make_adder->add_line( 'sub {' ); $make_adder->increase_indent; $make_adder->add_line( 'my $other_addend = shift;' ); $make_adder->add_gap; $make_adder->add_line( 'return ' . $varname . ' + $other_addend;' ); $make_adder->decrease_indent; $make_adder->add_line( '}' ); my $adder = $make_adder->compile; say $adder->( 2 ); ## ==> 42
This module is covered by the Type-Tiny stability policy.
If a variable already exists in the environment with that name, will instead add a variable with a different name and return that name. You should always continue to refer to the variable with that returned name, just in case.
As an alternative, "add_placeholder" returns a coderef, which you can call like "$callback->( @lines_of_code )".
Options are passed on to "eval_closure" from Eval::TypeTiny, but cannot include "code" or "environment". "alias => 1" is probably the option most likely to be useful, but in general you won't need to provide any options.
Please report any bugs to <https://github.com/tobyink/p5-type-tiny/issues>.
Eval::TypeTiny.
Toby Inkster <tobyink@cpan.org>.
This software is copyright (c) 2022-2023 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2023-02-01 | perl v5.36.0 |