{
    "mode": "perldoc",
    "parameter": "POE::Filter::Map",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/POE%3A%3AFilter%3A%3AMap/json",
    "generated": "2026-06-13T13:58:51Z",
    "synopsis": "#!perl\nuse POE qw(\nWheel::FollowTail\nFilter::Line Filter::Map Filter::Stackable\n);\nPOE::Session->create(\ninlinestates => {\nstart => sub {\nmy $parseinputaslines = POE::Filter::Line->new();\nmy $redactsomelines = POE::Filter::Map->new(\nCode => sub {\nmy $input = shift;\n$input = \"[REDACTED]\" unless $input =~ /sudo\\[\\d+\\]/i;\nreturn $input;\n},\n);\nmy $filterstack = POE::Filter::Stackable->new(\nFilters => [\n$parseinputaslines, # first on get, last on put\n$redactsomelines, # 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;",
    "sections": {
        "NAME": {
            "content": "POE::Filter::Map - transform input and/or output within a filter stack\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "#!perl\n\nuse POE qw(\nWheel::FollowTail\nFilter::Line Filter::Map Filter::Stackable\n);\n\nPOE::Session->create(\ninlinestates => {\nstart => sub {\nmy $parseinputaslines = POE::Filter::Line->new();\n\nmy $redactsomelines = POE::Filter::Map->new(\nCode => sub {\nmy $input = shift;\n$input = \"[REDACTED]\" unless $input =~ /sudo\\[\\d+\\]/i;\nreturn $input;\n},\n);\n\nmy $filterstack = POE::Filter::Stackable->new(\nFilters => [\n$parseinputaslines, # first on get, last on put\n$redactsomelines, # 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::Map transforms data inside the filter stack. It may be used to transform input,\noutput, or both depending on how it is constructed. This filter is named and modeled after\nPerl's built-in map() function.\n\nPOE::Filter::Map is designed to be combined with other filters through POE::Filter::Stackable.\nIn the \"SYNOPSIS\" example, a filter stack is created to parse logs as lines and redact all\nentries that don't pertain to a sudo process.\n",
            "subsections": []
        },
        "PUBLIC FILTER METHODS": {
            "content": "In addition to the usual POE::Filter methods, POE::Filter::Map also supports the following.\n\nnew",
            "subsections": [
                {
                    "name": "new",
                    "content": "parameter, or both a Put and a Get parameter. The values for Code, Put and Get are code\nreferences that, when invoked, return transformed versions of their sole parameters. A Code\nfunction will be used for both input and output, while Get and Put functions allow input and\noutput to be filtered in different ways.\n\n# Decrypt rot13.\nsub decryptrot13 {\nmy $encrypted = shift;\n$encrypted =~ tr[a-zA-Z][n-za-mN-ZA-M];\nreturn $encrypted;\n}\n\n# Encrypt rot13.\nsub encryptrot13 {\nmy $plaintext = shift;\n$plaintext =~ tr[a-zA-Z][n-za-mN-ZA-M];\nreturn $plaintext;\n}\n\n# Decrypt rot13 on input, and encrypt it on output.\nmy $rot13transcrypter = POE::Filter::Map->new(\nGet => \\&decryptrot13,\nPut => \\&encryptrot13,\n);\n\nRot13 is symmetric, so the above example can be simplified to use a single Code function.\n\nmy $rot13transcrypter = POE::Filter::Map->new(\nCode => sub {\nlocal $ = shift;\ntr[a-zA-Z][n-za-mN-ZA-M];\nreturn $;\n}\n);\n\nmodify"
                },
                {
                    "name": "modify",
                    "content": "parameters as new(), and it replaces the existing transforms with new ones.\n\n# Switch to \"reverse\" encryption for testing.\n$rot13transcrypter->modify(\nCode => sub { return scalar reverse shift }\n);\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "POE::Filter for more information about filters in general.\n\nPOE::Filter::Stackable for more details on stacking filters.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "None known.\n\nAUTHORS & COPYRIGHTS\nThe Map filter was contributed by Dieter Pearcey. Documentation is provided by Rocco Caputo.\n\nPlease see the POE manpage for more information about authors and contributors.\n",
            "subsections": []
        }
    },
    "summary": "POE::Filter::Map - transform input and/or output within a filter stack",
    "flags": [],
    "examples": [],
    "see_also": []
}