{
    "content": [
        {
            "type": "text",
            "text": "# Template::Plugin::Directory (perldoc)\n\n## NAME\n\nTemplate::Plugin::Directory - Plugin for generating directory listings\n\n## SYNOPSIS\n\n[% USE dir = Directory(dirpath) %]\n# files returns list of regular files\n[% FOREACH file = dir.files %]\n[% file.name %] [% file.path %] ...\n[% END %]\n# dirs returns list of sub-directories\n[% FOREACH subdir = dir.dirs %]\n[% subdir.name %] [% subdir.path %] ...\n[% END %]\n# list returns both interleaved in order\n[% FOREACH item = dir.list %]\n[% IF item.isdir %]\nDirectory: [% item.name %]\n[% ELSE %]\nFile: [% item.name %]\n[% END %]\n[% END %]\n# define a VIEW to display dirs/files\n[% VIEW myview %]\n[% BLOCK file %]\nFile: [% item.name %]\n[% END %]\n[% BLOCK directory %]\nDirectory: [% item.name %]\n[% item.content(myview) | indent -%]\n[% END %]\n[% END %]\n# display directory content using view\n[% myview.print(dir) %]\n\n## DESCRIPTION\n\nThis Template Toolkit plugin provides a simple interface to directory listings. It is derived\nfrom the Template::Plugin::File module and uses Template::Plugin::File object instances to\nrepresent files within a directory. Sub-directories within a directory are represented by\nfurther \"Template::Plugin::Directory\" instances.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **AUTHORS**\n- **COPYRIGHT**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Template::Plugin::Directory",
        "section": "",
        "mode": "perldoc",
        "summary": "Template::Plugin::Directory - Plugin for generating directory listings",
        "synopsis": "[% USE dir = Directory(dirpath) %]\n# files returns list of regular files\n[% FOREACH file = dir.files %]\n[% file.name %] [% file.path %] ...\n[% END %]\n# dirs returns list of sub-directories\n[% FOREACH subdir = dir.dirs %]\n[% subdir.name %] [% subdir.path %] ...\n[% END %]\n# list returns both interleaved in order\n[% FOREACH item = dir.list %]\n[% IF item.isdir %]\nDirectory: [% item.name %]\n[% ELSE %]\nFile: [% item.name %]\n[% END %]\n[% END %]\n# define a VIEW to display dirs/files\n[% VIEW myview %]\n[% BLOCK file %]\nFile: [% item.name %]\n[% END %]\n[% BLOCK directory %]\nDirectory: [% item.name %]\n[% item.content(myview) | indent -%]\n[% END %]\n[% END %]\n# display directory content using view\n[% myview.print(dir) %]",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 36,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 147,
                "subsections": []
            },
            {
                "name": "AUTHORS",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Template::Plugin::Directory - Plugin for generating directory listings\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "[% USE dir = Directory(dirpath) %]\n\n# files returns list of regular files\n[% FOREACH file = dir.files %]\n[% file.name %] [% file.path %] ...\n[% END %]\n\n# dirs returns list of sub-directories\n[% FOREACH subdir = dir.dirs %]\n[% subdir.name %] [% subdir.path %] ...\n[% END %]\n\n# list returns both interleaved in order\n[% FOREACH item = dir.list %]\n[% IF item.isdir %]\nDirectory: [% item.name %]\n[% ELSE %]\nFile: [% item.name %]\n[% END %]\n[% END %]\n\n# define a VIEW to display dirs/files\n[% VIEW myview %]\n[% BLOCK file %]\nFile: [% item.name %]\n[% END %]\n\n[% BLOCK directory %]\nDirectory: [% item.name %]\n[% item.content(myview) | indent -%]\n[% END %]\n[% END %]\n\n# display directory content using view\n[% myview.print(dir) %]\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This Template Toolkit plugin provides a simple interface to directory listings. It is derived\nfrom the Template::Plugin::File module and uses Template::Plugin::File object instances to\nrepresent files within a directory. Sub-directories within a directory are represented by\nfurther \"Template::Plugin::Directory\" instances.\n\nThe constructor expects a directory name as an argument.\n\n[% USE dir = Directory('/tmp') %]\n\nIt then provides access to the files and sub-directories contained within the directory.\n\n# regular files (not directories)\n[% FOREACH file IN dir.files %]\n[% file.name %]\n[% END %]\n\n# directories only\n[% FOREACH file IN dir.dirs %]\n[% file.name %]\n[% END %]\n\n# files and/or directories\n[% FOREACH file IN dir.list %]\n[% file.name %] ([% file.isdir ? 'directory' : 'file' %])\n[% END %]\n\nThe plugin constructor will throw a \"Directory\" error if the specified path does not exist, is\nnot a directory or fails to \"stat()\" (see Template::Plugin::File). Otherwise, it will scan the\ndirectory and create lists named '\"files\"' containing files, '\"dirs\"' containing directories and\n'\"list\"' containing both files and directories combined. The \"nostat\" option can be set to\ndisable all file/directory checks and directory scanning.\n\nEach file in the directory will be represented by a Template::Plugin::File object instance, and\neach directory by another \"Template::Plugin::Directory\". If the \"recurse\" flag is set, then\nthose directories will contain further nested entries, and so on. With the \"recurse\" flag unset,\nas it is by default, then each is just a place marker for the directory and does not contain any\nfurther content unless its \"scan()\" method is explicitly called. The \"isdir\" flag can be tested\nagainst files and/or directories, returning true if the item is a directory or false if it is a\nregular file.\n\n[% FOREACH file = dir.list %]\n[% IF file.isdir %]\n* Directory: [% file.name %]\n[% ELSE %]\n* File: [% file.name %]\n[% END %]\n[% END %]\n\nThis example shows how you might walk down a directory tree, displaying content as you go. With\nthe recurse flag disabled, as is the default, we need to explicitly call the \"scan()\" method on\neach directory, to force it to lookup files and further sub-directories contained within.\n\n[% USE dir = Directory(dirpath) %]\n* [% dir.path %]\n[% INCLUDE showdir %]\n\n[% BLOCK showdir -%]\n[% FOREACH file = dir.list -%]\n[% IF file.isdir -%]\n* [% file.name %]\n[% file.scan -%]\n[% INCLUDE showdir dir=file FILTER indent(4) -%]\n[% ELSE -%]\n- [% f.name %]\n[% END -%]\n[% END -%]\n[% END %]\n\nThis example is adapted (with some re-formatting for clarity) from a test in t/directry.t which\nproduces the following output:\n\n* test/dir\n- file1\n- file2\n* subone\n- bar\n- foo\n* subtwo\n- waz.html\n- wiz.html\n- xyzfile\n\nThe \"recurse\" flag can be set (disabled by default) to cause the constructor to automatically\nrecurse down into all sub-directories, creating a new \"Template::Plugin::Directory\" object for\neach one and filling it with any further content. In this case there is no need to explicitly\ncall the \"scan()\" method.\n\n[% USE dir = Directory(dirpath, recurse=1) %]\n...\n\n[% IF file.isdir -%]\n* [% file.name %]\n[% INCLUDE showdir dir=file FILTER indent(4) -%]\n[% ELSE -%]\n...\n\nThe directory plugin also provides support for views. A view can be defined as a \"VIEW ... END\"\nblock and should contain \"BLOCK\" definitions for files ('\"file\"') and directories\n('\"directory\"').\n\n[% VIEW myview %]\n[% BLOCK file %]\n- [% item.name %]\n[% END %]\n\n[% BLOCK directory %]\n* [% item.name %]\n[% item.content(myview) FILTER indent %]\n[% END %]\n[% END %]\n\nThe view \"print()\" method can then be called, passing the \"Directory\" object as an argument.\n\n[% USE dir = Directory(dirpath, recurse=1) %]\n[% myview.print(dir) %]\n\nWhen a directory is presented to a view, either as \"[% myview.print(dir) %]\" or \"[%\ndir.present(view) %]\", then the \"directory\" \"BLOCK\" within the \"myview\" \"VIEW\" is processed. The\n\"item\" variable will be set to alias the \"Directory\" object.\n\n[% BLOCK directory %]\n* [% item.name %]\n[% item.content(myview) FILTER indent %]\n[% END %]\n\nIn this example, the directory name is first printed and the content(view) method is then called\nto present each item within the directory to the view. Further directories will be mapped to the\n\"directory\" block, and files will be mapped to the \"file\" block.\n\nWith the recurse option disabled, as it is by default, the \"directory\" block should explicitly\ncall a \"scan()\" on each directory.\n\n[% VIEW myview %]\n[% BLOCK file %]\n- [% item.name %]\n[% END %]\n\n[% BLOCK directory %]\n* [% item.name %]\n[% item.scan %]\n[% item.content(myview) FILTER indent %]\n[% END %]\n[% END %]\n\n[% USE dir = Directory(dirpath) %]\n[% myview.print(dir) %]\n",
                "subsections": []
            },
            "AUTHORS": {
                "content": "Michael Stevens wrote the original Directory plugin on which this is based. Andy Wardley split\nit into separate File and Directory plugins, added some extra code and documentation for \"VIEW\"\nsupport, and made a few other minor tweaks.\n",
                "subsections": []
            },
            "COPYRIGHT": {
                "content": "Copyright (C) 2000-2007 Michael Stevens, Andy Wardley.\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::Plugin, Template::Plugin::File, Template::View\n",
                "subsections": []
            }
        }
    }
}