{
    "content": [
        {
            "type": "text",
            "text": "# POE::Filter::Stackable (perldoc)\n\n## NAME\n\nPOE::Filter::Stackable - combine multiple POE::Filter objects\n\n## SYNOPSIS\n\n#!perl\nuse POE qw(\nWheel::FollowTail\nFilter::Line Filter::Grep Filter::Stackable\n);\nPOE::Session->create(\ninlinestates => {\nstart => sub {\nmy $parseinputaslines = POE::Filter::Line->new();\nmy $selectsudologlines = POE::Filter::Grep->new(\nPut => sub { 1 },\nGet => sub {\nmy $input = shift;\nreturn $input =~ /sudo\\[\\d+\\]/i;\n},\n);\nmy $filterstack = POE::Filter::Stackable->new(\nFilters => [\n$parseinputaslines, # first on get, last on put\n$selectsudologlines, # first on put, last on get\n]\n);\n$[HEAP]{tailor} = POE::Wheel::FollowTail->new(\nFilename => \"/var/log/system.log\",\nInputEvent => \"gotlogline\",\nFilter => $filterstack,\n);\n},\ngotlogline => sub {\nprint \"Log: $[ARG0]\\n\";\n}\n}\n);\nPOE::Kernel->run();\nexit;\n\n## DESCRIPTION\n\nPOE::Filter::Stackable combines multiple filters together in such a way that they appear to be a\nsingle filter. All the usual POE::Filter methods work, but data is secretly passed through the\nstacked filters before it is returned. POE::Wheel objects and stand-alone programs need no\nmodifications to work with a filter stack.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION** (1 subsections)\n- **PUBLIC FILTER METHODS** (4 subsections)\n- **SEE ALSO**\n- **BUGS**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "POE::Filter::Stackable",
        "section": "",
        "mode": "perldoc",
        "summary": "POE::Filter::Stackable - combine multiple POE::Filter objects",
        "synopsis": "#!perl\nuse POE qw(\nWheel::FollowTail\nFilter::Line Filter::Grep Filter::Stackable\n);\nPOE::Session->create(\ninlinestates => {\nstart => sub {\nmy $parseinputaslines = POE::Filter::Line->new();\nmy $selectsudologlines = POE::Filter::Grep->new(\nPut => sub { 1 },\nGet => sub {\nmy $input = shift;\nreturn $input =~ /sudo\\[\\d+\\]/i;\n},\n);\nmy $filterstack = POE::Filter::Stackable->new(\nFilters => [\n$parseinputaslines, # first on get, last on put\n$selectsudologlines, # first on put, last on get\n]\n);\n$[HEAP]{tailor} = POE::Wheel::FollowTail->new(\nFilename => \"/var/log/system.log\",\nInputEvent => \"gotlogline\",\nFilter => $filterstack,\n);\n},\ngotlogline => sub {\nprint \"Log: $[ARG0]\\n\";\n}\n}\n);\nPOE::Kernel->run();\nexit;",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 42,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 15,
                "subsections": [
                    {
                        "name": "put",
                        "lines": 3
                    }
                ]
            },
            {
                "name": "PUBLIC FILTER METHODS",
                "lines": 35,
                "subsections": [
                    {
                        "name": "push",
                        "lines": 12
                    },
                    {
                        "name": "unshift",
                        "lines": 3
                    },
                    {
                        "name": "filters",
                        "lines": 8
                    },
                    {
                        "name": "filter_types",
                        "lines": 12
                    }
                ]
            },
            {
                "name": "SEE ALSO",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 7,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "POE::Filter::Stackable - combine multiple POE::Filter objects\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "#!perl\n\nuse POE qw(\nWheel::FollowTail\nFilter::Line Filter::Grep Filter::Stackable\n);\n\nPOE::Session->create(\ninlinestates => {\nstart => sub {\nmy $parseinputaslines = POE::Filter::Line->new();\n\nmy $selectsudologlines = POE::Filter::Grep->new(\nPut => sub { 1 },\nGet => sub {\nmy $input = shift;\nreturn $input =~ /sudo\\[\\d+\\]/i;\n},\n);\n\nmy $filterstack = POE::Filter::Stackable->new(\nFilters => [\n$parseinputaslines, # first on get, last on put\n$selectsudologlines, # first on put, last on get\n]\n);\n\n$[HEAP]{tailor} = POE::Wheel::FollowTail->new(\nFilename => \"/var/log/system.log\",\nInputEvent => \"gotlogline\",\nFilter => $filterstack,\n);\n},\ngotlogline => sub {\nprint \"Log: $[ARG0]\\n\";\n}\n}\n);\n\nPOE::Kernel->run();\nexit;\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "POE::Filter::Stackable combines multiple filters together in such a way that they appear to be a\nsingle filter. All the usual POE::Filter methods work, but data is secretly passed through the\nstacked filters before it is returned. POE::Wheel objects and stand-alone programs need no\nmodifications to work with a filter stack.\n\nIn the \"SYNOPSIS\", POE::Filter::Line and POE::Filter::Grep are combined into one filter that\nonly returns a particular kind of line. This can be more efficient than filtering lines in\napplication space, as fewer events may need to be dispatched and handled.\n\nInternally, filters are stored in an array.\n\nData added by getonestart() will flow through the filter array in increasing index order.\nFilter #0 will have first crack at it, followed by filter #1 and so. The getone() call will\nreturn an item after it has passed through the last filter.\n",
                "subsections": [
                    {
                        "name": "put",
                        "content": "with the highest index first, and put() will return the results after data has passed through\nfilter #0.\n"
                    }
                ]
            },
            "PUBLIC FILTER METHODS": {
                "content": "In addition to the usual POE::Filter methods, POE::Filter::Stackable also supports the\nfollowing.\n\nnew\nBy default, new() creates an empty filter stack that behaves like POE::Filter::Stream. It may be\ngiven optional parameters to initialize the stack with an array of filters.\n\nmy $sudolines = POE::Filter::Stackable->new(\nFilters => [\nPOE::Filter::Line->new(),\nPOE::Filter::Grep->new(\nPut => sub { 1 }, # put all items\nGet => sub { shift() =~ /sudo\\[\\d+\\]/i },\n),\n]\n);\n\npop\nBehaves like Perl's built-in pop() for the filter stack. The highest-indexed filter is removed\nfrom the stack and returned. Any data remaining in the filter's input buffer is lost, but an\napplication may always call \"getpending\" in POE::Filter on the returned filter.\n\nmy $lastfilter = $stackable->pop();\nmy $lastbuffer = $lastfilter->getpending();\n\nshift\nBehaves like Perl's built-in shift() for the filter stack. The 0th filter is removed from the\nstack and returned. Any data remaining in the filter's input buffer is passed to the new head of\nthe stack, or it is lost if the stack becomes empty. An application may also call \"getpending\"\nin POE::Filter on the returned filter to examine the filter's input buffer.\n\nmy $firstfilter = $stackable->shift();\nmy $firstbuffer = $firstfilter->getpending();\n\npush FILTER[, FILTER]",
                "subsections": [
                    {
                        "name": "push",
                        "content": "process input last, and they will handle output first.\n\n# Reverse data read through the stack.\n# rot13 encode data sent through the stack.\n$stackable->push(\nPOE::Filter::Map->(\nGet => sub { return scalar reverse shift() },\nPut => sub { local $ = shift(); tr[a-zA-Z][n-za-mN-ZA-M]; $ },\n)\n);\n\nunshift FILTER[, FILTER]"
                    },
                    {
                        "name": "unshift",
                        "content": "FILTERs will process input first, and they will handle output last.\n\nfilters"
                    },
                    {
                        "name": "filters",
                        "content": "order.\n\nCalling \"$filterstack->filters()\" in the \"SYNOPSIS\" would return a list of two filter objects:\n\nPOE::Filter::Line=ARRAY(0x8b5ee0)\nPOE::Filter::Grep=ARRAY(0x8b5f7c)\n\nfiltertypes"
                    },
                    {
                        "name": "filter_types",
                        "content": "order.\n\nCalling \"$filterstack->filtertypes()\" in the \"SYNOPSIS\" would return a list of two class\nnames:\n\nPOE::FIlter::Line\nPOE::Filter::Grep\n\nIt could easily be replaced by:\n\nmy @filtertypes = map { ref } $filterstack->filters;\n"
                    }
                ]
            },
            "SEE ALSO": {
                "content": "POE::Filter for more information about filters in general.\n\nSpecific filters, amongst which are: POE::Filter::Block, POE::Filter::Grep, POE::Filter::HTTPD,\nPOE::Filter::Line, POE::Filter::Map, POE::Filter::RecordBlock, POE::Filter::Reference,\nPOE::Filter::Stream\n",
                "subsections": []
            },
            "BUGS": {
                "content": "None currently known.\n\nAUTHORS & COPYRIGHTS\nThe Stackable filter was contributed by Dieter Pearcey. Documentation provided by Rocco Caputo.\n\nPlease see the POE manpage for more information about authors and contributors.\n",
                "subsections": []
            }
        }
    }
}