{
    "content": [
        {
            "type": "text",
            "text": "# Tie::Memoize (perldoc)\n\n**Summary:** Tie::Memoize - add data to hash when needed\n\n**Synopsis:** require Tie::Memoize;\ntie %hash, 'Tie::Memoize',\n\\&fetch,                  # The rest is optional\n$DATA, \\&exists,\n{%inivalue}, {%iniexistence};\n\n## Examples\n\n- `sub slurp {`\n- `my ($key, $dir) = shift;`\n- `open my $h, '<', \"$dir/$key\" or return;`\n- `local $/; <$h>                      # slurp it all`\n- `sub exists { my ($key, $dir) = shift; return -f \"$dir/$key\" }`\n- `tie %hash, 'Tie::Memoize', \\&slurp, $directory, \\&exists,`\n- `{ fakefile1 => $content1, fakefile2 => $content2 },`\n- `{ pretenddoesnotexists => 0, knowntoexist => 1 };`\n- `This example treats the slightly modified contents of $directory as a hash. The modifications`\n- `are that the keys fakefile1 and fakefile2 fetch values $content1 and $content2, and`\n- `pretenddoesnotexists will never be accessed. Additionally, the existence of knowntoexist is`\n- `never checked (so if it does not exists when its content is needed, the user of %hash may be`\n- `confused).`\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (6 lines)\n- **DESCRIPTION** (16 lines)\n- **Inheriting from Tie::Memoize** (11 lines)\n- **EXAMPLE** (17 lines)\n- **BUGS** (3 lines)\n- **AUTHOR** (2 lines)\n\n## Full Content\n\n### NAME\n\nTie::Memoize - add data to hash when needed\n\n### SYNOPSIS\n\nrequire Tie::Memoize;\ntie %hash, 'Tie::Memoize',\n\\&fetch,                  # The rest is optional\n$DATA, \\&exists,\n{%inivalue}, {%iniexistence};\n\n### DESCRIPTION\n\nThis package allows a tied hash to autoload its values on the first access, and to use the\ncached value on the following accesses.\n\nOnly read-accesses (via fetching the value or \"exists\") result in calls to the functions; the\nmodify-accesses are performed as on a normal hash.\n\nThe required arguments during \"tie\" are the hash, the package, and the reference to the\n\"FETCH\"ing function. The optional arguments are an arbitrary scalar $data, the reference to the\n\"EXISTS\" function, and initial values of the hash and of the existence cache.\n\nBoth the \"FETCH\"ing function and the \"EXISTS\" functions have the same signature: the arguments\nare \"$key, $data\"; $data is the same value as given as argument during tie()ing. Both functions\nshould return an empty list if the value does not exist. If \"EXISTS\" function is different from\nthe \"FETCH\"ing function, it should return a TRUE value on success. The \"FETCH\"ing function\nshould return the intended value if the key is valid.\n\n### Inheriting from Tie::Memoize\n\nThe structure of the tied() data is an array reference with elements\n\n0:  cache of known values\n1:  cache of known existence of keys\n2:  FETCH  function\n3:  EXISTS function\n4:  $data\n\nThe rest is for internal usage of this package. In particular, if TIEHASH is overwritten, it\nshould call SUPER::TIEHASH.\n\n### EXAMPLE\n\nsub slurp {\nmy ($key, $dir) = shift;\nopen my $h, '<', \"$dir/$key\" or return;\nlocal $/; <$h>                      # slurp it all\n}\nsub exists { my ($key, $dir) = shift; return -f \"$dir/$key\" }\n\ntie %hash, 'Tie::Memoize', \\&slurp, $directory, \\&exists,\n{ fakefile1 => $content1, fakefile2 => $content2 },\n{ pretenddoesnotexists => 0, knowntoexist => 1 };\n\nThis example treats the slightly modified contents of $directory as a hash. The modifications\nare that the keys fakefile1 and fakefile2 fetch values $content1 and $content2, and\npretenddoesnotexists will never be accessed. Additionally, the existence of knowntoexist is\nnever checked (so if it does not exists when its content is needed, the user of %hash may be\nconfused).\n\n### BUGS\n\nFIRSTKEY and NEXTKEY methods go through the keys which were already read, not all the possible\nkeys of the hash.\n\n### AUTHOR\n\nIlya Zakharevich <mailto:perl-module-hash-memoize@ilyaz.org>.\n\n"
        }
    ],
    "structuredContent": {
        "command": "Tie::Memoize",
        "section": "",
        "mode": "perldoc",
        "summary": "Tie::Memoize - add data to hash when needed",
        "synopsis": "require Tie::Memoize;\ntie %hash, 'Tie::Memoize',\n\\&fetch,                  # The rest is optional\n$DATA, \\&exists,\n{%inivalue}, {%iniexistence};",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [
            "sub slurp {",
            "my ($key, $dir) = shift;",
            "open my $h, '<', \"$dir/$key\" or return;",
            "local $/; <$h>                      # slurp it all",
            "sub exists { my ($key, $dir) = shift; return -f \"$dir/$key\" }",
            "tie %hash, 'Tie::Memoize', \\&slurp, $directory, \\&exists,",
            "{ fakefile1 => $content1, fakefile2 => $content2 },",
            "{ pretenddoesnotexists => 0, knowntoexist => 1 };",
            "This example treats the slightly modified contents of $directory as a hash. The modifications",
            "are that the keys fakefile1 and fakefile2 fetch values $content1 and $content2, and",
            "pretenddoesnotexists will never be accessed. Additionally, the existence of knowntoexist is",
            "never checked (so if it does not exists when its content is needed, the user of %hash may be",
            "confused)."
        ],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 16,
                "subsections": []
            },
            {
                "name": "Inheriting from Tie::Memoize",
                "lines": 11,
                "subsections": []
            },
            {
                "name": "EXAMPLE",
                "lines": 17,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Tie::Memoize - add data to hash when needed\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "require Tie::Memoize;\ntie %hash, 'Tie::Memoize',\n\\&fetch,                  # The rest is optional\n$DATA, \\&exists,\n{%inivalue}, {%iniexistence};\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This package allows a tied hash to autoload its values on the first access, and to use the\ncached value on the following accesses.\n\nOnly read-accesses (via fetching the value or \"exists\") result in calls to the functions; the\nmodify-accesses are performed as on a normal hash.\n\nThe required arguments during \"tie\" are the hash, the package, and the reference to the\n\"FETCH\"ing function. The optional arguments are an arbitrary scalar $data, the reference to the\n\"EXISTS\" function, and initial values of the hash and of the existence cache.\n\nBoth the \"FETCH\"ing function and the \"EXISTS\" functions have the same signature: the arguments\nare \"$key, $data\"; $data is the same value as given as argument during tie()ing. Both functions\nshould return an empty list if the value does not exist. If \"EXISTS\" function is different from\nthe \"FETCH\"ing function, it should return a TRUE value on success. The \"FETCH\"ing function\nshould return the intended value if the key is valid.\n",
                "subsections": []
            },
            "Inheriting from Tie::Memoize": {
                "content": "The structure of the tied() data is an array reference with elements\n\n0:  cache of known values\n1:  cache of known existence of keys\n2:  FETCH  function\n3:  EXISTS function\n4:  $data\n\nThe rest is for internal usage of this package. In particular, if TIEHASH is overwritten, it\nshould call SUPER::TIEHASH.\n",
                "subsections": []
            },
            "EXAMPLE": {
                "content": "sub slurp {\nmy ($key, $dir) = shift;\nopen my $h, '<', \"$dir/$key\" or return;\nlocal $/; <$h>                      # slurp it all\n}\nsub exists { my ($key, $dir) = shift; return -f \"$dir/$key\" }\n\ntie %hash, 'Tie::Memoize', \\&slurp, $directory, \\&exists,\n{ fakefile1 => $content1, fakefile2 => $content2 },\n{ pretenddoesnotexists => 0, knowntoexist => 1 };\n\nThis example treats the slightly modified contents of $directory as a hash. The modifications\nare that the keys fakefile1 and fakefile2 fetch values $content1 and $content2, and\npretenddoesnotexists will never be accessed. Additionally, the existence of knowntoexist is\nnever checked (so if it does not exists when its content is needed, the user of %hash may be\nconfused).\n",
                "subsections": []
            },
            "BUGS": {
                "content": "FIRSTKEY and NEXTKEY methods go through the keys which were already read, not all the possible\nkeys of the hash.\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Ilya Zakharevich <mailto:perl-module-hash-memoize@ilyaz.org>.\n",
                "subsections": []
            }
        }
    }
}