Eval::TypeTiny(3)
π Eval::TypeTiny β the manual, but make it cute π
okay bestie, gather round, because this one is genuinely iconic. this is the Eval::TypeTiny(3) page β a lil module that evaluates a string of Perl code in a clean environment. that's the whole vibe. π¦
β¨ STATUS β¨
this module is covered by the Type-Tiny stability policy. so likeβ¦ it's stable, it's committed, it's not gonna ghost you. π
πΈ DESCRIPTION πΈ
so Type::Tiny uses this thing to do two jobs:
- compile coderefs out of strings of Perl code
- and compile hashrefs of variables to close over
that's it. that's the job. no cap.
π Functions π
by default this module exports one function, and it works much like the similarly named function from Eval::Closure:
eval_closure(source => $source, environment => \%env, %opt)
other functions can be imported on request β like, you gotta ask for them, they're not just gonna show up:
set_subname( $fully_qualified_name, $coderef )β works like the similarly named function from Sub::Util, except it will fallback to doing absolutely nothing if neither Sub::Util nor Sub::Name are available. also? it will cowardly refuse to set the name of a coderef a second time if it's already named it. boundaries! we love them. πtype_to_coderef( $type, %options )β turns a Type::Tiny object into a coderef, suitable for installing into a symbol table to create a function likeArrayReforInt. (actually it should work for any object which providesis_parameterizable,parameterize, andqualified_namemethods, such as Type::Coercion.) π
$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. so future-you knows what's up.
the coderef will be named using set_subname unless $options{anonymous} is true. (anonymous? mysterious? we respect it. πΆοΈ)
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. manifesting fr fr π«
π Constants π
the following constants may be exported, but are not by default. you gotta ask, bestie.
HAS_LEXICAL_SUBSβ boolean indicating whether Eval::TypeTiny has support for lexical subs. (this feature requires Perl 5.18.) βALIAS_IMPLEMENTATIONβ returns a string indicating what implementation ofalias => 1is being used. Eval::TypeTiny will automatically choose the best implementation. this constant can be matched against theIMPLEMENTATION_*constants. π―IMPLEMENTATION_NATIVEβ ifALIAS_IMPLEMENTATION eq IMPLEMENTATION_NATIVEthen Eval::TypeTiny is currently using Perl 5.22's native alias feature. this requires Perl 5.22. π§IMPLEMENTATION_DEVEL_LEXALIASβ ifALIAS_IMPLEMENTATION eq IMPLEMENTATION_DEVEL_LEXALIASthen Eval::TypeTiny is currently using Devel::LexAlias to provide aliases. πIMPLEMENTATION_PADWALKERβ ifALIAS_IMPLEMENTATION eq IMPLEMENTATION_PADWALKERthen Eval::TypeTiny is currently using PadWalker to provide aliases. π¦IMPLEMENTATION_TIEβ ifALIAS_IMPLEMENTATION eq IMPLEMENTATION_TIEthen Eval::TypeTiny is using the fallback implementation of aliases usingtie. this is the slowest implementation, and may cause problems in certain edge cases, like trying to alias already-tied variables, but it's the only way to implementalias => 1without a recent version of Perl or one of the two optional modules mentioned above. it's giving last-resort-iconic. πNICE_PROTOTYPESβ if this is true, thentype_to_coderefwill give parameterizable type constraints the slightly nicer prototype of(;$)instead of the default(;@). this allows constructs like:
ArrayRef[Int] | HashRef[Int]
β¦ to "just work". slay. π
π₯ EVALUATION ENVIRONMENT π₯
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.) so like, strict mode said yes, warnings said no thanks. π«Ά
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");
see? put it inside the string. self-sufficient queen. π
π BUGS π
please report any bugs to <https://github.com/tobyink/p5-type-tiny/issues>. do not suffer in silence, bestie, that's not the vibe. π
π SEE ALSO π
Eval::Closure, Error::TypeTiny::Compilation. go read those too, iykyk. π
π«Ά AUTHOR π«Ά
Toby Inkster <tobyink@cpan.org>.
π COPYRIGHT AND LICENCE π
this software is copyright (c) 2013-2014, 2017-2025 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. free as in, go off. ποΈ
π DISCLAIMER OF WARRANTIES π
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.
okay so like β this part is yelling and it's yelling for a reason. no promises, no guarantees, use at your own risk. periodt. π¨
and that's the whole page, bestie!! π this was Eval::TypeTiny(3) from perl v5.42.0, dated 2026-01-17 β go forth and compile coderefs from strings responsibly, mwah πβ¨πΈ
π¦ where this page comes from
- fedora 44: perl-Type-Tiny 2.010001-2.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms