{
    "content": [
        {
            "type": "text",
            "text": "# Template::Document (perldoc)\n\n## NAME\n\nTemplate::Document - Compiled template document object\n\n## SYNOPSIS\n\nuse Template::Document;\n$doc = Template::Document->new({\nBLOCK => sub { # some perl code; return $sometext },\nDEFBLOCKS => {\nheader => sub { # more perl code; return $sometext },\nfooter => sub { # blah blah blah; return $sometext },\n},\nMETADATA => {\nauthor  => 'Andy Wardley',\nversion => 3.14,\n}\n}) || die $Template::Document::ERROR;\nprint $doc->process($context);\n\n## DESCRIPTION\n\nThis module defines an object class whose instances represent compiled template documents. The\nTemplate::Parser module creates a \"Template::Document\" instance to encapsulate a template as it\nis compiled into Perl code.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **METHODS**\n- **CLASS METHODS**\n- **INTERNAL FUNCTIONS**\n- **AUTHOR**\n- **COPYRIGHT**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Template::Document",
        "section": "",
        "mode": "perldoc",
        "summary": "Template::Document - Compiled template document object",
        "synopsis": "use Template::Document;\n$doc = Template::Document->new({\nBLOCK => sub { # some perl code; return $sometext },\nDEFBLOCKS => {\nheader => sub { # more perl code; return $sometext },\nfooter => sub { # blah blah blah; return $sometext },\n},\nMETADATA => {\nauthor  => 'Andy Wardley',\nversion => 3.14,\n}\n}) || die $Template::Document::ERROR;\nprint $doc->process($context);",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 16,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 41,
                "subsections": []
            },
            {
                "name": "METHODS",
                "lines": 49,
                "subsections": []
            },
            {
                "name": "CLASS METHODS",
                "lines": 25,
                "subsections": []
            },
            {
                "name": "INTERNAL FUNCTIONS",
                "lines": 9,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Template::Document - Compiled template document object\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use Template::Document;\n\n$doc = Template::Document->new({\nBLOCK => sub { # some perl code; return $sometext },\nDEFBLOCKS => {\nheader => sub { # more perl code; return $sometext },\nfooter => sub { # blah blah blah; return $sometext },\n},\nMETADATA => {\nauthor  => 'Andy Wardley',\nversion => 3.14,\n}\n}) || die $Template::Document::ERROR;\n\nprint $doc->process($context);\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This module defines an object class whose instances represent compiled template documents. The\nTemplate::Parser module creates a \"Template::Document\" instance to encapsulate a template as it\nis compiled into Perl code.\n\nThe constructor method, new(), expects a reference to a hash array containing the \"BLOCK\",\n\"DEFBLOCKS\" and \"METADATA\" items.\n\nThe \"BLOCK\" item should contain a reference to a Perl subroutine or a textual representation of\nPerl code, as generated by the Template::Parser module. This is then evaluated into a subroutine\nreference using \"eval()\".\n\nThe \"DEFLOCKS\" item should reference a hash array containing further named \"BLOCK\"s which may be\ndefined in the template. The keys represent \"BLOCK\" names and the values should be subroutine\nreferences or text strings of Perl code as per the main \"BLOCK\" item.\n\nThe \"METADATA\" item should reference a hash array of metadata items relevant to the document.\n\nThe process() method can then be called on the instantiated \"Template::Document\" object, passing\na reference to a Template::Context object as the first parameter. This will install any locally\ndefined blocks (\"DEFBLOCKS\") in the \"BLOCKS\" cache in the context (via a call to visit()) so\nthat they may be subsequently resolved by the context. The main \"BLOCK\" subroutine is then\nexecuted, passing the context reference on as a parameter. The text returned from the template\nsubroutine is then returned by the process() method, after calling the context leave() method to\npermit cleanup and de-registration of named \"BLOCKS\" previously installed.\n\nAn \"AUTOLOAD\" method provides access to the \"METADATA\" items for the document. The\nTemplate::Service module installs a reference to the main \"Template::Document\" object in the\nstash as the \"template\" variable. This allows metadata items to be accessed from within\ntemplates, including \"PREPROCESS\" templates.\n\nheader:\n\n<html>\n<head>\n<title>[% template.title %]\n</head>\n...\n\n\"Template::Document\" objects are usually created by the Template::Parser but can be manually\ninstantiated or sub-classed to provide custom template components.\n",
                "subsections": []
            },
            "METHODS": {
                "content": "new(\\%config)\nConstructor method which accept a reference to a hash array containing the structure as shown in\nthis example:\n\n$doc = Template::Document->new({\nBLOCK => sub { # some perl code; return $sometext },\nDEFBLOCKS => {\nheader => sub { # more perl code; return $sometext },\nfooter => sub { # blah blah blah; return $sometext },\n},\nMETADATA => {\nauthor  => 'Andy Wardley',\nversion => 3.14,\n}\n}) || die $Template::Document::ERROR;\n\n\"BLOCK\" and \"DEFBLOCKS\" items may be expressed as references to Perl subroutines or as text\nstrings containing Perl subroutine definitions, as is generated by the Template::Parser module.\nThese are evaluated into subroutine references using \"eval()\".\n\nReturns a new \"Template::Document\" object or \"undef\" on error. The error() class method can be\ncalled, or the $ERROR package variable inspected to retrieve the relevant error message.\n\nprocess($context)\nMain processing routine for the compiled template document. A reference to a Template::Context\nobject should be passed as the first parameter. The method installs any locally defined blocks\nvia a call to the context visit() method, processes its own template, (passing the context\nreference as a parameter) and then calls leave() in the context to allow cleanup.\n\nprint $doc->process($context);\n\nReturns a text string representing the generated output for the template. Errors are thrown via\n\"die()\".\n\nblock()\nReturns a reference to the main \"BLOCK\" subroutine.\n\nblocks()\nReturns a reference to the hash array of named \"DEFBLOCKS\" subroutines.\n\nvariables()\nReturns a reference to a hash of variables used in the template. This requires the TRACEVARS\noption to be enabled.\n\nAUTOLOAD\nAn autoload method returns \"METADATA\" items.\n\nprint $doc->author();\n",
                "subsections": []
            },
            "CLASS METHODS": {
                "content": "These methods are used internally.\n\nasperl($content)\nThis method generate a Perl representation of the template.\n\nmy $perl = Template::Document->asperl({\nBLOCK     => $mainblock,\nDEFBLOCKS => {\nfoo   => $fooblock,\nbar   => $barblock,\n},\nMETADATA  => {\nname  => 'mytemplate',\n}\n});\n\nwriteperlfile(\\%config)\nThis method is used to write compiled Perl templates to disk. If the \"COMPILEEXT\" option (to\nindicate a file extension for saving compiled templates) then the Template::Parser module calls\nthis subroutine before calling the new() constructor. At this stage, the parser has a\nrepresentation of the template as text strings containing Perl code. We can write that to a\nfile, enclosed in a small wrapper which will allow us to subsequently \"require()\" the file and\nhave Perl parse and compile it into a \"Template::Document\". Thus we have persistence of compiled\ntemplates.\n",
                "subsections": []
            },
            "INTERNAL FUNCTIONS": {
                "content": "catchwarnings()\nThis is a simple handler used to catch any errors that arise when the compiled Perl template is\nfirst evaluated (that is, evaluated by Perl to create a template subroutine at compile, rather\nthan the template being processed at runtime).\n\nisutf8()\nThis is mapped to \"utf8::isutf8\" for versions of Perl that have it (> 5.008) or to\n\"Encode::isutf8\" for Perl 5.008. Earlier versions of Perl are not supported.\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Andy Wardley <abw@wardley.org> <http://wardley.org/>\n",
                "subsections": []
            },
            "COPYRIGHT": {
                "content": "Copyright (C) 1996-2013 Andy Wardley. All Rights Reserved.\n\nThis module is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "Template, Template::Parser\n",
                "subsections": []
            }
        }
    }
}