{
    "content": [
        {
            "type": "text",
            "text": "# Data::Visitor (perldoc)\n\n## NAME\n\nData::Visitor - Visitor style traversal of Perl data structures\n\n## SYNOPSIS\n\n# NOTE\n# You probably want to use Data::Visitor::Callback for trivial things\npackage FooCounter;\nuse Moose;\nextends qw(Data::Visitor);\nhas numberoffoos => (\nisa => \"Int\",\nis  => \"rw\",\ndefault => 0,\n);\nsub visitvalue {\nmy ( $self, $data ) = @;\nif ( defined $data and $data eq \"foo\" ) {\n$self->numberoffoos( $self->numberoffoos + 1 );\n}\nreturn $data;\n}\nmy $counter = FooCounter->new;\n$counter->visit( {\nthis => \"that\",\nsomefoos => [ qw/foo foo bar foo/ ],\ntheother => \"foo\",\n});\n$counter->numberoffoos; # this is now 4\n\n## DESCRIPTION\n\nThis module is a simple visitor implementation for Perl values.\n\n## Sections\n\n- **NAME**\n- **VERSION**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **METHODS**\n- **RETURN VALUE**\n- **SUBCLASSING**\n- **TODO**\n- **SEE ALSO**\n- **SUPPORT**\n- **AUTHORS**\n- **CONTRIBUTORS**\n- **COPYRIGHT AND LICENCE**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Data::Visitor",
        "section": "",
        "mode": "perldoc",
        "summary": "Data::Visitor - Visitor style traversal of Perl data structures",
        "synopsis": "# NOTE\n# You probably want to use Data::Visitor::Callback for trivial things\npackage FooCounter;\nuse Moose;\nextends qw(Data::Visitor);\nhas numberoffoos => (\nisa => \"Int\",\nis  => \"rw\",\ndefault => 0,\n);\nsub visitvalue {\nmy ( $self, $data ) = @;\nif ( defined $data and $data eq \"foo\" ) {\n$self->numberoffoos( $self->numberoffoos + 1 );\n}\nreturn $data;\n}\nmy $counter = FooCounter->new;\n$counter->visit( {\nthis => \"that\",\nsomefoos => [ qw/foo foo bar foo/ ],\ntheother => \"foo\",\n});\n$counter->numberoffoos; # this is now 4",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "VERSION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 34,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "METHODS",
                "lines": 80,
                "subsections": []
            },
            {
                "name": "RETURN VALUE",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "SUBCLASSING",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "TODO",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "SUPPORT",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "AUTHORS",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "CONTRIBUTORS",
                "lines": 10,
                "subsections": []
            },
            {
                "name": "COPYRIGHT AND LICENCE",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Data::Visitor - Visitor style traversal of Perl data structures\n",
                "subsections": []
            },
            "VERSION": {
                "content": "version 0.31\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "# NOTE\n# You probably want to use Data::Visitor::Callback for trivial things\n\npackage FooCounter;\nuse Moose;\n\nextends qw(Data::Visitor);\n\nhas numberoffoos => (\nisa => \"Int\",\nis  => \"rw\",\ndefault => 0,\n);\n\nsub visitvalue {\nmy ( $self, $data ) = @;\n\nif ( defined $data and $data eq \"foo\" ) {\n$self->numberoffoos( $self->numberoffoos + 1 );\n}\n\nreturn $data;\n}\n\nmy $counter = FooCounter->new;\n\n$counter->visit( {\nthis => \"that\",\nsomefoos => [ qw/foo foo bar foo/ ],\ntheother => \"foo\",\n});\n\n$counter->numberoffoos; # this is now 4\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This module is a simple visitor implementation for Perl values.\n\nIt has a main dispatcher method, \"visit\", which takes a single perl value and then calls the\nmethods appropriate for that value.\n\nIt can recursively map (cloning as necessary) or just traverse most structures, with support for\nper object behavior, circular structures, visiting tied structures, and all ref types (hashes,\narrays, scalars, code, globs).\n\nData::Visitor is meant to be subclassed, but also ships with a callback driven subclass,\nData::Visitor::Callback.\n",
                "subsections": []
            },
            "METHODS": {
                "content": "visit $data\nThis method takes any Perl value as its only argument, and dispatches to the various other\nvisiting methods using \"visitnoreccheck\", based on the data's type.\n\nIf the value is a reference and has already been seen then \"visitseen\" is called.\n\nvisitseen $data, $firstresult\nWhen an already seen value is encountered again, it is typically replaced with the result of\nthe first visitation of that value. The value and the result of the first visitation are\npassed as arguments.\n\nReturns $firstresult.\n\nvisitnoreccheck $data\nCalled for any value that has not yet been seen. Does the actual type based dispatch for\n\"visit\".\n\nShould not be called directly unless forcing a circular structure to be unfolded. Use with\ncaution as this may cause infinite recursion.\n\nvisitobject $object\nIf the value is a blessed object, \"visit\" calls this method. The base implementation will\njust forward to \"visitvalue\".\n\nvisitref $value\nGeneric recursive visitor. All non blessed values are given to this.\n\n\"visitobject\" can delegate to this method in order to visit the object anyway.\n\nThis will check if the visitor can handle \"visit$reftype\" (lowercase), and if not delegate\nto \"visitvalue\" instead.\n\nvisitarray $arrayref\nvisithash $hashref\nvisitglob $globref\nvisitcode $coderef\nvisitscalar $scalarref\nThese methods are called for the corresponding container type.\n\nvisitvalue $value\nIf the value is anything else, this method is called. The base implementation will return\n$value.\n\nvisithashentries $hash\nvisithashentry $key, $value, $hash\nDelegates to \"visithashkey\" and \"visithashvalue\". The value is passed as $[2] so that\nit is aliased.\n\nvisithashkey $key, $value, $hash\nCalls \"visit\" on the key and returns it.\n\nvisithashvalue $value, $key, $hash\nThe value will be aliased (passed as $[1]).\n\nvisitarrayentries $array\nvisitarrayentry $value, $index, $array\nDelegates to \"visit\" on value. The value is passed as $[1] to retain aliasing.\n\nvisittied $object, $var\nWhen \"tiedasobjects\" is enabled and a tied variable (hash, array, glob or scalar) is\nencountered this method will be called on the tied object. If a valid mapped value is\nreturned, the newly constructed result container will be tied to the return value and no\niteration of the contents of the data will be made (since all storage is delegated to the\ntied object).\n\nIf a non blessed value is returned from \"visittied\" then the structure will be iterated\nnormally, and the result container will not be tied at all.\n\nThis is because tying to the same class and performing the tie operations will not yield the\nsame results in many cases.\n\nretainmagic $orig, $copy\nCopies over magic from $orig to $copy.\n\nCurrently only handles \"bless\". In the future this might be expanded using Variable::Magic\nbut it isn't clear what the correct semantics for magic copying should be.\n\ntrace\nCalled if the \"DEBUG\" constant is set with a trace message.\n",
                "subsections": []
            },
            "RETURN VALUE": {
                "content": "This object can be used as an \"fmap\" of sorts - providing an ad-hoc functor interface for Perl\ndata structures.\n\nIn void context this functionality is ignored, but in any other context the default methods will\nall try to return a value of similar structure, with its children also fmapped.\n",
                "subsections": []
            },
            "SUBCLASSING": {
                "content": "Data::Visitor is a Moose class, so it should be subclassed using Moose.\n\nThen override the callback methods in any way you like. To retain visitor behavior, make sure to\nretain the functionality of \"visitarray\" and \"visithash\".\n",
                "subsections": []
            },
            "TODO": {
                "content": "*   Add support for \"natural\" visiting of trees.\n\n*   Expand \"retainmagic\" to support tying at the very least, or even more with Variable::Magic\nif possible.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "Data::Rmap, Tree::Simple::VisitorFactory, Data::Traverse\n\n<http://en.wikipedia.org/wiki/Visitorpattern>,\n<http://www.ninebynine.org/Software/Learning-Haskell-Notes.html#functors>,\n<http://en.wikipedia.org/wiki/Functor>\n",
                "subsections": []
            },
            "SUPPORT": {
                "content": "Bugs may be submitted through the RT bug tracker\n<https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Visitor> (or\nbug-Data-Visitor@rt.cpan.org <mailto:bug-Data-Visitor@rt.cpan.org>).\n",
                "subsections": []
            },
            "AUTHORS": {
                "content": "*   Yuval Kogman <nothingmuch@woobling.org>\n\n*   Marcel Grünauer <marcel@cpan.org>\n",
                "subsections": []
            },
            "CONTRIBUTORS": {
                "content": "*   Jesse Luehrs <doy@tozt.net>\n\n*   Florian Ragwitz <rafl@debian.org>\n\n*   Karen Etheridge <ether@cpan.org>\n\n*   David Steinbrunner <dsteinbrunner@pobox.com>\n\n*   Robin Smidsrød <robin@smidsrod.no>\n",
                "subsections": []
            },
            "COPYRIGHT AND LICENCE": {
                "content": "This software is copyright (c) 2020 by Yuval Kogman.\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": []
            }
        }
    }
}