Eval::T...umulator(3)
π Eval::TypeTiny::CodeAccumulator β the manual, but make it a group chat π
okay so bestie, you're reading the manual page for Eval::TypeTiny::CodeAccumulator(3) (the terminal chops it down to Eval::T...umulator(3) because it's β¨a long nameβ¨ and honestly? iconic). This lives in the User Contributed Perl Documentation and it's here to teach you a whole other way to do the Eval::TypeTiny thing. buckle up π
πΈ NAME πΈ
Eval::TypeTiny::CodeAccumulator β an alternative API for Eval::TypeTiny. that's it, that's the name, she's serving β¨alternativeβ¨
π¦ SYNOPSIS π¦
look at this lil cutie building a function line by line like it's legos:
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
42. periodt. the math is mathing π
π STATUS π
This module is covered by the Type-Tiny stability policy. so like, it's official, it's vetted, it's got its papers π«Ά
β¨ DESCRIPTION β¨
π§ Constructor
new( %attrs )β builds you a fresh accumulator. the only attribute supported rn isdescription. that's the whole menu bestie, one item, and she eats π
π Methods
env()β hands you back the current compilation environment: a hashref of variables that are gonna get closed over. very "here's the friend group you're bringing along" energy.code()β gives you the source code you've written so far. the WIP, the draft, the rough cut β¨description()β returns that same description you handed to the constructor, if you gave one at all. no description? no problem, you just get nothing back. πadd_line( @lines_of_code )β drops in the next line of code. pls and thank you.addf( $fmt, @args )β it's just a shortcut foradd_line( sprintf $fmt, @args ). same vibe, fewer keystrokes πadd_gap()β adds a blank line of code. a lil breathing room, a lil pause for the girlies πincrease_indent()β bumps the indentation level up for all the lines of code that come after. main character lines get more space, obviously.decrease_indent()β brings that indentation level back down for subsequent lines. we love a girl who knows when to step back πΈadd_variable( $varname, $reference_to_value )β adds a variable into the compilation environment so the coderef being generated can close over it. π€
real talk though: if a variable with that name already exists in the environment, it won't clobber it β instead it adds a variable under a different name and returns that name to you. so always keep referring to the variable by the name it hands back, just in case. iykyk, don't be out here hardcoding names π
add_placeholder( $placeholder_name )β adds a line of code that's literally just a comment, but it remembers the line number for later. it's a sticky note. it's a "brb" message. it's bookmarking but for code β¨fill_placeholder( $placeholder_name, @lines_of_code )β goes back to a placeholder you inserted earlier and swaps it out for actual code. coming back to finish what you started, we love growth π
as an alternative, add_placeholder returns a coderef, which you can call like $callback->( @lines_of_code ). two paths, same destination, pick your fighter π«Ά
compile( %opts )β compiles the code and returns it to you as a coderef. boom, function. π₯
options get passed on to eval_closure from Eval::TypeTiny, but they cannot include code or environment β those two are off limits, no exceptions bestie. alias => 1 is probably the option most likely to be useful, but honestly in general you won't need to provide any options at all. lowkey a no-notes situation.
finalize()β this one gets called bycompileright before it compiles the code. all it does is remove unfilled placeholder comments. it is not intended for end users to call, but it's documented anyway because it might be a useful hook if you're subclassing this class. it's giving "for the developers only" energy π but we're telling you anyway because transparency slays.
π©Ή BUGS π©Ή
found a bug? spill. report any bugs to <https://github.com/tobyink/p5-type-tiny/issues>. the link is right there, use it, don't be shy π
π SEE ALSO π
- Eval::TypeTiny. β that's the one. go read her too π
π AUTHOR π
Toby Inkster <tobyink@cpan.org>. yes, the icon, the legend, the moment π
π COPYRIGHT AND LICENCE π
This software is copyright (c) 2022-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. so like, it's free free. go wild (responsibly) π¦
π¨ 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 bestie this is the part where we're fr fr: AS IS, no promises, no guarantees, no warranty of any kind. the all-caps is not me being dramatic, that's just how the lawyers type. no cap π
and that's the whole page!! this was perl v5.42.0, dated 2026-01-17, and you just read Eval::T...umulator(3) from the User Contributed Perl Documentation. mwah, go compile something gorgeous π
β¨π«Ά
π¦ 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