Eval::TypeTiny(3) User Contributed Perl Documentation Eval::TypeTiny(3)

# [NAME](#NAME)

Eval::TypeTiny - utility to evaluate a string of Perl code in a clean environment

# [STATUS](#STATUS)

This module is covered by the Type-Tiny stability policy.

# [DESCRIPTION](#DESCRIPTION)

This module is used by Type::Tiny to compile coderefs from strings of Perl code, and hashrefs of variables to close over.

## [Functions](#Functions)

By default this module exports one function, which works much like the similarly named function from Eval::Closure:

"eval\_closure(source =&gt; $source, environment =&gt; \\%env, %opt)"

Other functions can be imported on request:

"set\_subname( $fully\_qualified\_name, $coderef )"

Works like the similarly named function from Sub::Util, but will fallback to doing nothing if neither Sub::Util nor Sub::Name are available. Also will cowardly refuse the set the name of a coderef a second time if it's already named it.

"type\_to\_coderef( $type, %options )"

Turns a Type::Tiny object into a coderef, suitable for installing into a symbol table to create a function like "ArrayRef" or "Int". (Actually should work for any object which provides "is\_parameterizable", "parameterize", and "qualified\_name" methods, 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 '-&gt;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.

## [Constants](#Constants)

The following constants may be exported, but are not by default.

"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 of "alias =&gt; 1" is being used. Eval::TypeTiny will automatically choose the best implementation. This constant can be matched against the "IMPLEMENTATION\_\*" constants.

"IMPLEMENTATION\_NATIVE"

If "ALIAS\_IMPLEMENTATION eq IMPLEMENTATION\_NATIVE" then Eval::TypeTiny is currently using Perl 5.22's native alias feature. This requires Perl 5.22.

"IMPLEMENTATION\_DEVEL\_LEXALIAS"

If "ALIAS\_IMPLEMENTATION eq IMPLEMENTATION\_DEVEL\_LEXALIAS" then Eval::TypeTiny is currently using Devel::LexAlias to provide aliases.

"IMPLEMENTATION\_PADWALKER"

If "ALIAS\_IMPLEMENTATION eq IMPLEMENTATION\_PADWALKER" then Eval::TypeTiny is currently using PadWalker to provide aliases.

"IMPLEMENTATION\_TIE"

If "ALIAS\_IMPLEMENTATION eq IMPLEMENTATION\_TIE" then Eval::TypeTiny is using the fallback implementation of aliases using "tie". 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 implement "alias =&gt; 1" without a recent version of Perl or one of the two optional modules mentioned above.

"NICE\_PROTOTYPES"

If this is true, then type\_to\_coderef will give parameterizable type constraints the slightly nicer prototype of "(;$)" instead of the default "(;@)". This allows constructs like:

```
   ArrayRef[Int] | HashRef[Int]
    
```

... to "just work".

# [EVALUATION ENVIRONMENT](#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.)

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");
```

# [BUGS](#BUGS)

Please report any bugs to &lt;https://github.com/tobyink/p5-type-tiny/issues&gt;.

# [SEE ALSO](#SEE_ALSO)

Eval::Closure, Error::TypeTiny::Compilation.

# [AUTHOR](#AUTHOR)

Toby Inkster &lt;tobyink@cpan.org&gt;.

# [COPYRIGHT AND LICENCE](#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.

# [DISCLAIMER OF WARRANTIES](#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.

2026-10-26 perl v5.44.0

---

Document: Eval::TypeTiny(3pm) from perl-type-tiny 2.010001-r5 (Chainguard OS)
Source: https://github.com/tobyink/p5-type-tiny
