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 is description. 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 for add_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 by compile right 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 🌟


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