GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Eval::TypeTiny::CodeAccumulator(3) User Contributed Perl Documentation Eval::TypeTiny::CodeAccumulator(3)

Eval::TypeTiny::CodeAccumulator - alternative API for Eval::TypeTiny

  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

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

The only currently supported attribute is "description".

Returns the current compilation environment, a hashref of variables to close over.
Returns the source code so far.
Returns the same description given to the constructor, if any.
Adds the next line of code.
"addf( $fmt, @args )"
Shortcut for "add_line( sprintf $fmt, @args )".
Adds a blank line of code.
Increases the indentation level for subsequent lines of code.
Decreases the indentation level for subsequent lines of code.
"add_variable( $varname, $reference_to_value )"
Adds a variable to the compilation environment so that the coderef being generated can close over it.

If a variable already exists in the environment with that name, will instead add a variable with a different name and return that name. You should always continue to refer to the variable with that returned name, just in case.

Adds a line of code which is just a comment, but remembers its line number.
"fill_placeholder( $placeholder_name, @lines_of_code )"
Goes back to a previously inserted placeholder and replaces it with code.

As an alternative, "add_placeholder" returns a coderef, which you can call like $callback->( @lines_of_code ).

Compiles the code and returns it as a coderef.

Options are passed on to "eval_closure" from Eval::TypeTiny, but cannot include "code" or "environment". "alias => 1" is probably the option most likely to be useful, but in general you won't need to provide any options.

This method is called by "compile" just before compiling the code. All it does is remove unfilled placeholder comments. It is not intended for end users to call, but is documented as it may be a useful hook if you are subclassing this class.

Please report any bugs to <https://github.com/tobyink/p5-type-tiny/issues>.

Eval::TypeTiny.

Toby Inkster <tobyink@cpan.org>.

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.

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.

2025-04-30 perl v5.40.2

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.