Eval::TypeTiny(3pm) | User Contributed Perl Documentation | Eval::TypeTiny(3pm) |
Eval::TypeTiny - utility to evaluate a string of Perl code in a clean environment
This module is covered by the Type-Tiny stability policy.
This module is used by Type::Tiny to compile coderefs from strings of Perl code, and hashrefs of variables to close over.
By default this module exports one function, which works much like the similarly named function from Eval::Closure:
Other functions can be imported on request:
$options{post_method} can be a string of Perl indicating a method to call on the type constraint before returning it. For example '->moose_type'.
$options{description} can be a description of the coderef which may be shown in stack traces, etc.
The coderef will be named using "set_subname" unless $options{anonymous} is true.
If $type is undef, then it is assumed that the type constraint hasn't been defined yet but will later, yet you still want a function now. $options{type_library} and $options{type_name} will be used to find the type constraint when the function gets called.
The following constants may be exported, but are not by default.
ArrayRef[Int] | HashRef[Int]
... to "just work".
The evaluation is performed in the presence of strict, but the absence of warnings. (This is different to Eval::Closure which enables warnings for compiled closures.)
The feature pragma is not active in the evaluation environment, so the following will not work:
use feature qw(say); use Eval::TypeTiny qw(eval_closure); my $say_all = eval_closure( source => 'sub { say for @_ }', ); $say_all->("Hello", "World");
The feature pragma does not "carry over" into the stringy eval. It is of course possible to import pragmas into the evaluated string as part of the string itself:
use Eval::TypeTiny qw(eval_closure); my $say_all = eval_closure( source => 'sub { use feature qw(say); say for @_ }', ); $say_all->("Hello", "World");
Please report any bugs to <https://github.com/tobyink/p5-type-tiny/issues>.
Eval::Closure, Error::TypeTiny::Compilation.
Toby Inkster <tobyink@cpan.org>.
This software is copyright (c) 2013-2014, 2017-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 |