POE::Filter::Map(3pm)
π POE::Filter::Map β the manual page, but make it cute β¨
okay bestie, so POE::Filter::Map is a Perl thing from the User Contributed Perl Documentation squad, and it's basically the glow-up your data gets on the way through a filter stack. transforming input and/or output? yeah. that's the whole vibe. π¦
β¨ SYNOPSIS β¨
like, here's the whole thing in action, no notes, iconic behaviour:
#!perl
use POE qw(
Wheel::FollowTail
Filter::Line Filter::Map Filter::Stackable
);
POE::Session->create(
inline_states => {
_start => sub {
my $parse_input_as_lines = POE::Filter::Line->new();
my $redact_some_lines = POE::Filter::Map->new(
Code => sub {
my $input = shift;
$input = "[REDACTED]" unless $input =~ /sudo\[\d+\]/i;
return $input;
},
);
my $filter_stack = POE::Filter::Stackable->new(
Filters => [
$parse_input_as_lines, # first on get, last on put
$redact_some_lines, # first on put, last on get
]
);
$_[HEAP]{tailor} = POE::Wheel::FollowTail->new(
Filename => "/var/log/system.log",
InputEvent => "got_log_line",
Filter => $filter_stack,
);
},
got_log_line => sub {
print "Log: $_[ARG0]\n";
}
}
);
POE::Kernel->run();
exit;
πΈ DESCRIPTION πΈ
so POE::Filter::Map transforms data inside the filter stack. it can do input, output, or both β depends on how you construct it, bestie. it's literally named and modeled after Perl's built-in map() function, which, slay. π
and the way it's designed to be combined with other filters through POE::Filter::Stackable? obsessed. in that "SYNOPSIS" example up there, a filter stack gets created to parse logs as lines and redact every entry that doesn't pertain to a sudo process. so all the not-sudo stuff gets the [REDACTED] treatment. privacy queen behaviour. π
π PUBLIC FILTER METHODS π
on top of the usual POE::Filter methods, POE::Filter::Map also supports these:
π« new
new() constructs a new POE::Filter::Map object. it must either be called with a single Code parameter, or both a Put and a Get parameter. no half-measures, pick a lane.
the values for Code, Put and Get are code references that, when invoked, return transformed versions of their sole parameters. a Code function gets used for both input and output, while Get and Put functions let input and output be filtered in different ways. very versatile of them honestly.
# Decrypt rot13.
sub decrypt_rot13 {
my $encrypted = shift;
$encrypted =~ tr[a-zA-Z][n-za-mN-ZA-M];
return $encrypted;
}
# Encrypt rot13.
sub encrypt_rot13 {
my $plaintext = shift;
$plaintext =~ tr[a-zA-Z][n-za-mN-ZA-M];
return $plaintext;
}
# Decrypt rot13 on input, and encrypt it on output.
my $rot13_transcrypter = POE::Filter::Map->new(
Get => \&decrypt_rot13,
Put => \&encrypt_rot13,
);
ngl rot13 is symmetric, so that whole example can be simplified down to a single Code function. less code, same energy:
my $rot13_transcrypter = POE::Filter::Map->new(
Code => sub {
local $_ = shift;
tr[a-zA-Z][n-za-mN-ZA-M];
return $_;
}
);
π« modify
modify() changes a POE::Filter::Map object's behavior at run-time. it accepts the same parameters as new(), and it replaces the existing transforms with new ones. glow-up mid-operation, we love to see it. π¦
# Switch to "reverse" encryption for testing.
$rot13_transcrypter->modify(
Code => sub { return scalar reverse shift }
);
π SEE ALSO π
POE::Filterfor more information about filters in general.POE::Filter::Stackablefor more details on stacking filters.
π BUGS π
None known.
like, no known bugs?? we stan a flawless filter. πβ¨
π«Ά AUTHORS & COPYRIGHTS π«Ά
The Map filter was contributed by Dieter Pearcey. Documentation is provided by Rocco Caputo. absolute icons, ty for your service. π
Please see the POE manpage for more information about authors and contributors.
okay that's the whole thing, bestie!! you're now fully fluent in POE::Filter::Map. go transform some data, you main character. π
π
this page came from perl v5.34.0, dated 2022-03-25, and it's page POE::Filter::Map(3pm) of the User Contributed Perl Documentation β mwah, bye!! π
π¦ where this page comes from
- debian bookworm: libpoe-perl 2:1.3700-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libpoe-perl 2:1.3700-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libpoe-perl 2:1.3700-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu questing: libpoe-perl 2:1.3700-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms