{
    "mode": "perldoc",
    "parameter": "Eval::TypeTiny::CodeAccumulator",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Eval%3A%3ATypeTiny%3A%3ACodeAccumulator/json",
    "generated": "2026-10-04T14:24:13Z",
    "synopsis": "my $makeadder = 'Eval::TypeTiny::CodeAccumulator'->new(\ndescription => 'adder',\n);\nmy $n = 40;\nmy $varname = $makeadder->addvariable( '$addend' => \\$n );\n$makeadder->addline( 'sub {' );\n$makeadder->increaseindent;\n$makeadder->addline( 'my $otheraddend = shift;' );\n$makeadder->addgap;\n$makeadder->addline( 'return ' . $varname . ' + $otheraddend;' );\n$makeadder->decreaseindent;\n$makeadder->addline( '}' );\nmy $adder = $makeadder->compile;\nsay $adder->( 2 );  ## ==> 42",
    "sections": {
        "NAME": {
            "content": "Eval::TypeTiny::CodeAccumulator - alternative API for Eval::TypeTiny\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "my $makeadder = 'Eval::TypeTiny::CodeAccumulator'->new(\ndescription => 'adder',\n);\n\nmy $n = 40;\nmy $varname = $makeadder->addvariable( '$addend' => \\$n );\n\n$makeadder->addline( 'sub {' );\n$makeadder->increaseindent;\n$makeadder->addline( 'my $otheraddend = shift;' );\n$makeadder->addgap;\n$makeadder->addline( 'return ' . $varname . ' + $otheraddend;' );\n$makeadder->decreaseindent;\n$makeadder->addline( '}' );\n\nmy $adder = $makeadder->compile;\n\nsay $adder->( 2 );  ## ==> 42\n",
            "subsections": []
        },
        "STATUS": {
            "content": "This module is covered by the Type-Tiny stability policy.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "",
            "subsections": [
                {
                    "name": "Constructor",
                    "content": ""
                },
                {
                    "name": "new",
                    "content": "The only currently supported attribute is \"description\".\n"
                },
                {
                    "name": "Methods",
                    "content": ""
                },
                {
                    "name": "env",
                    "content": "Returns the current compilation environment, a hashref of variables to close over.\n"
                },
                {
                    "name": "code",
                    "content": "Returns the source code so far.\n"
                },
                {
                    "name": "description",
                    "content": "Returns the same description given to the constructor, if any.\n"
                },
                {
                    "name": "add_line",
                    "content": "Adds the next line of code.\n"
                },
                {
                    "name": "add_gap",
                    "content": "Adds a blank line of code.\n"
                },
                {
                    "name": "increase_indent",
                    "content": "Increases the indentation level for subsequent lines of code.\n"
                },
                {
                    "name": "decrease_indent",
                    "content": "Decreases the indentation level for subsequent lines of code.\n\n\"addvariable( $varname, $referencetovalue )\"\nAdds a variable to the compilation environment so that the coderef being generated can close\nover it.\n\nIf a variable already exists in the environment with that name, will instead add a variable\nwith a different name and return that name. You should always continue to refer to the\nvariable with that returned name, just in case.\n"
                },
                {
                    "name": "add_placeholder",
                    "content": "Adds a line of code which is just a comment, but remembers its line number.\n\n\"fillplaceholder( $placeholdername, @linesofcode )\"\nGoes back to a previously inserted placeholder and replaces it with code.\n\nAs an alternative, \"addplaceholder\" returns a coderef, which you can call like $callback->(\n@linesofcode ).\n"
                },
                {
                    "name": "compile",
                    "content": "Compiles the code and returns it as a coderef.\n\nOptions are passed on to \"evalclosure\" from Eval::TypeTiny, but cannot include \"code\" or\n\"environment\". \"alias => 1\" is probably the option most likely to be useful, but in general\nyou won't need to provide any options.\n"
                },
                {
                    "name": "finalize",
                    "content": "This method is called by \"compile\" just before compiling the code. All it does is remove\nunfilled placeholder comments. It is not intended for end users to call, but is documented\nas it may be a useful hook if you are subclassing this class.\n"
                }
            ]
        },
        "BUGS": {
            "content": "Please report any bugs to <https://github.com/tobyink/p5-type-tiny/issues>.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Eval::TypeTiny.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Toby Inkster <tobyink@cpan.org>.\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENCE": {
            "content": "This software is copyright (c) 2022-2023 by Toby Inkster.\n\nThis is free software; you can redistribute it and/or modify it under the same terms as the Perl\n5 programming language system itself.\n",
            "subsections": []
        },
        "DISCLAIMER OF WARRANTIES": {
            "content": "THIS PACKAGE IS PROVIDED \"AS IS\" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\nWITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.\n",
            "subsections": []
        }
    },
    "summary": "Eval::TypeTiny::CodeAccumulator - alternative API for Eval::TypeTiny",
    "flags": [],
    "examples": [],
    "see_also": []
}