{
    "content": [
        {
            "type": "text",
            "text": "# HTML::Template::Expr (perldoc)\n\n## NAME\n\nHTML::Template::Expr - HTML::Template extension adding expression support\n\n## SYNOPSIS\n\nuse HTML::Template::Expr;\nmy $template = HTML::Template::Expr->new(filename => 'foo.tmpl');\n$template->param(bananacount => 10);\nprint $template->output();\n\n## DESCRIPTION\n\nThis module provides an extension to HTML::Template which allows expressions in the template\nsyntax. This is purely an addition - all the normal HTML::Template options, syntax and behaviors\nwill still work. See HTML::Template for details.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **MOTIVATION**\n- **BASIC SYNTAX**\n- **COMPARISON**\n- **MATHEMATICS**\n- **LOGIC**\n- **FUNCTIONS**\n- **DEFINING NEW FUNCTIONS**\n- **MODPERL TIP**\n- **CAVEATS**\n- **BUGS**\n- **CREDITS**\n- **AUTHOR**\n- **LICENSE**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "HTML::Template::Expr",
        "section": "",
        "mode": "perldoc",
        "summary": "HTML::Template::Expr - HTML::Template extension adding expression support",
        "synopsis": "use HTML::Template::Expr;\nmy $template = HTML::Template::Expr->new(filename => 'foo.tmpl');\n$template->param(bananacount => 10);\nprint $template->output();",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 21,
                "subsections": []
            },
            {
                "name": "MOTIVATION",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "BASIC SYNTAX",
                "lines": 25,
                "subsections": []
            },
            {
                "name": "COMPARISON",
                "lines": 34,
                "subsections": []
            },
            {
                "name": "MATHEMATICS",
                "lines": 14,
                "subsections": []
            },
            {
                "name": "LOGIC",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "FUNCTIONS",
                "lines": 51,
                "subsections": []
            },
            {
                "name": "DEFINING NEW FUNCTIONS",
                "lines": 33,
                "subsections": []
            },
            {
                "name": "MODPERL TIP",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "CAVEATS",
                "lines": 10,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 11,
                "subsections": []
            },
            {
                "name": "CREDITS",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "LICENSE",
                "lines": 23,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "HTML::Template::Expr - HTML::Template extension adding expression support\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use HTML::Template::Expr;\n\nmy $template = HTML::Template::Expr->new(filename => 'foo.tmpl');\n$template->param(bananacount => 10);\nprint $template->output();\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This module provides an extension to HTML::Template which allows expressions in the template\nsyntax. This is purely an addition - all the normal HTML::Template options, syntax and behaviors\nwill still work. See HTML::Template for details.\n\nExpression support includes comparisons, math operations, string operations and a mechanism to\nallow you add your own functions at runtime. The basic syntax is:\n\n<TMPLIF EXPR=\"bananacount > 10\">\nI've got a lot of bananas.\n</TMPLIF>\n\nThis will output \"I've got a lot of bananas\" if you call:\n\n$template->param(bananacount => 100);\n\nIn your script. <TMPLVAR>s also work with expressions:\n\nI'd like to have <TMPLVAR EXPR=\"bananacount * 2\"> bananas.\n\nThis will output \"I'd like to have 200 bananas.\" with the same param() call as above.\n",
                "subsections": []
            },
            "MOTIVATION": {
                "content": "Some of you may wonder if I've been replaced by a pod person. Just for the record, I still think\nthis sort of thing should be avoided. However, I realize that there are some situations where\nallowing the template author some programmatic leeway can be invaluable.\n\nIf you don't like it, don't use this module. Keep using plain ol' HTML::Template - I know I\nwill! However, if you find yourself needing a little programming in your template, for whatever\nreason, then this module may just save you from HTML::Mason.\n",
                "subsections": []
            },
            "BASIC SYNTAX": {
                "content": "Variables are unquoted alphanumeric strings with the same restrictions as variable names in\nHTML::Template. Their values are set through param(), just like normal HTML::Template variables.\nFor example, these two lines are equivalent:\n\n<TMPLVAR EXPR=\"foo\">\n\n<TMPLVAR NAME=\"foo\">\n\nNumbers are unquoted strings of numbers and may have a single \".\" to indicate a floating point\nnumber. For example:\n\n<TMPLVAR EXPR=\"10 + 20.5\">\n\nString constants must be enclosed in quotes, single or double. For example:\n\n<TMPLVAR EXPR=\"sprintf('%d', foo)\">\n\nYou can string together operators to produce complex booleans:\n\n<TMPLIF EXPR=\"(foo || bar || baz || (bif && bing) || (bananas > 10))\">\nI'm in a complex situation.\n</TMPLIF>\n\nThe parser is pretty simple, so you may need to use parenthesis to get the desired precedence.\n",
                "subsections": []
            },
            "COMPARISON": {
                "content": "Here's a list of supported comparison operators:\n\n*   Numeric Comparisons\n\n*   <\n\n*   >\n\n*   ==\n\n*   !=\n\n*   >=\n\n*   <=\n\n*   <=>\n\n*   String Comparisons\n\n*   gt\n\n*   lt\n\n*   eq\n\n*   ne\n\n*   ge\n\n*   le\n\n*   cmp\n",
                "subsections": []
            },
            "MATHEMATICS": {
                "content": "The basic operators are supported:\n\n*   +\n\n*   -\n\n*   *\n\n*   /\n\n*   %\n\nThere are also some mathy functions. See the FUNCTIONS section below.\n",
                "subsections": []
            },
            "LOGIC": {
                "content": "Boolean logic is available:\n\n*   && (synonym: and)\n\n*   || (synonym: or)\n",
                "subsections": []
            },
            "FUNCTIONS": {
                "content": "The following functions are available to be used in expressions. See perldoc perlfunc for\ndetails.\n\n*   sprintf\n\n*   substr (2 and 3 arg versions only)\n\n*   lc\n\n*   lcfirst\n\n*   uc\n\n*   ucfirst\n\n*   length\n\n*   defined\n\n*   abs\n\n*   atan2\n\n*   cos\n\n*   exp\n\n*   hex\n\n*   int\n\n*   log\n\n*   oct\n\n*   rand\n\n*   sin\n\n*   sqrt\n\n*   srand\n\nAll functions must be called using full parenthesis. For example, this is a syntax error:\n\n<TMPLIF expr=\"defined foo\">\n\nBut this is good:\n\n<TMPLIF expr=\"defined(foo)\">\n",
                "subsections": []
            },
            "DEFINING NEW FUNCTIONS": {
                "content": "To define a new function, pass a \"functions\" option to new:\n\n$t = HTML::Template::Expr->new(filename => 'foo.tmpl',\nfunctions =>\n{ funcname => \\&funchandler });\n\nOr, you can use \"registerfunction\" class method to register the function globally:\n\nHTML::Template::Expr->registerfunction(funcname => \\&funchandler);\n\nYou provide a subroutine reference that will be called during output. It will receive as\narguments the parameters specified in the template. For example, here's a function that checks\nif a directory exists:\n\nsub directoryexists {\nmy $dirname = shift;\nreturn 1 if -d $dirname;\nreturn 0;\n}\n\nIf you call HTML::Template::Expr->new() with a \"functions\" arg:\n\n$t = HTML::Template::Expr->new(filename => 'foo.tmpl',\nfunctions => {\ndirectoryexists => \\&directoryexists\n});\n\nThen you can use it in your template:\n\n<tmplif expr=\"directoryexists('/home/sam')\">\n\nThis can be abused in ways that make my teeth hurt.\n",
                "subsections": []
            },
            "MODPERL TIP": {
                "content": "\"registerfunction\" class method can be called in modperl's startup.pl to define widely used\ncommon functions to HTML::Template::Expr. Add something like this to your startup.pl:\n\nuse HTML::Template::Expr;\n\nHTML::Template::Expr->registerfunction(foozicate => sub { ... });\nHTML::Template::Expr->registerfunction(barify    => sub { ... });\nHTML::Template::Expr->registerfunction(baznate   => sub { ... });\n\nYou might also want to pre-compile some commonly used templates and cache them. See\nHTML::Template's FAQ for instructions.\n",
                "subsections": []
            },
            "CAVEATS": {
                "content": "Currently the module forces the HTML::Template globalvars option to be set. This will hopefully\ngo away in a future version, so if you need globalvars in your templates then you should set it\nexplicitly.\n\nThe module won't work with HTML::Template's filecache or sharedcache modes, but normal memory\ncaching should work. I hope to address this is a future version.\n\nThe module is inefficient, both in parsing and evaluation. I'll be working on this for future\nversions and patches are always welcome.\n",
                "subsections": []
            },
            "BUGS": {
                "content": "I am aware of no bugs - if you find one, join the mailing list and tell us about it. You can\njoin the HTML::Template mailing-list by visiting:\n\nhttp://lists.sourceforge.net/lists/listinfo/html-template-users\n\nOf course, you can still email me directly (sam@tregar.com) with bugs, but I reserve the right\nto forward bug reports to the mailing list.\n\nWhen submitting bug reports, be sure to include full details, including the VERSION of the\nmodule, a test script and a test template demonstrating the problem!\n",
                "subsections": []
            },
            "CREDITS": {
                "content": "The following people have generously submitted bug reports, patches and ideas:\n\nPeter Leonard\nTatsuhiko Miyagawa\nDon Brodale\n\nThanks!\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Sam Tregar <sam@tregar.com>\n",
                "subsections": []
            },
            "LICENSE": {
                "content": "HTML::Template::Expr : HTML::Template extension adding expression support\n\nCopyright (C) 2001 Sam Tregar (sam@tregar.com)\n\nThis module is free software; you can redistribute it and/or modify it under the terms of\neither:\n\na) the GNU General Public License as published by the Free Software Foundation; either version\n1, or (at your option) any later version, or\n\nb) the \"Artistic License\" which comes with this module.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;\nwithout even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See\neither the GNU General Public License or the Artistic License for more details.\n\nYou should have received a copy of the Artistic License with this module, in the file ARTISTIC.\nIf not, I'll be glad to provide one.\n\nYou should have received a copy of the GNU General Public License along with this program; if\nnot, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\n02111-1307 USA\n",
                "subsections": []
            }
        }
    }
}