.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "POE::Filter::Grep 3pm" .TH POE::Filter::Grep 3pm "2020-02-07" "perl v5.30.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" POE::Filter::Grep \- select or remove items based on simple rules .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& #!perl \& \& use POE qw( \& Wheel::FollowTail \& Filter::Line Filter::Grep Filter::Stackable \& ); \& \& POE::Session\->create( \& inline_states => { \& _start => sub { \& my $parse_input_as_lines = POE::Filter::Line\->new(); \& \& my $select_sudo_log_lines = POE::Filter::Grep\->new( \& Put => sub { 1 }, \& Get => sub { \& my $input = shift; \& return $input =~ /sudo\e[\ed+\e]/i; \& }, \& ); \& \& my $filter_stack = POE::Filter::Stackable\->new( \& Filters => [ \& $parse_input_as_lines, # first on get, last on put \& $select_sudo_log_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]\en"; \& } \& } \& ); \& \& POE::Kernel\->run(); \& exit; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" POE::Filter::Grep selects or removes items based on simple tests. It may be used to filter input, output, or both. This filter is named and modeled after Perl's built-in \fBgrep()\fR function. .PP POE::Filter::Grep is designed to be combined with other filters through POE::Filter::Stackable. In the \*(L"\s-1SYNOPSIS\*(R"\s0 example, a filter stack is created to parse logs as lines and remove all entries that don't pertain to a sudo process. (Or if your glass is half full, the stack only selects entries that \s-1DO\s0 mention sudo.) .SH "PUBLIC FILTER METHODS" .IX Header "PUBLIC FILTER METHODS" In addition to the usual POE::Filter methods, POE::Filter::Grep also supports the following. .SS "new" .IX Subsection "new" \&\fBnew()\fR constructs a new POE::Filter::Grep object. It must either be called with a single Code parameter, or both a Put and a Get parameter. The values for Code, Put, and Get are code references that, when invoked, return true to select an item or false to reject it. A Code function will be used for both input and output, while Get and Put functions allow input and output to be filtered in different ways. The item in question will be passed as the function's sole parameter. .PP .Vb 5 \& sub reject_bidoofs { \& my $pokemon = shift; \& return 1 if $pokemon ne "bidoof"; \& return; \& } \& \& my $gotta_catch_nearly_all = POE::Filter::Grep\->new( \& Code => \e&reject_bidoofs, \& ); .Ve .PP Enforce read-only behavior: .PP .Vb 4 \& my $read_only = POE::Filter::Grep\->new( \& Get => sub { 1 }, \& Put => sub { 0 }, \& ); .Ve .SS "modify" .IX Subsection "modify" \&\fBmodify()\fR changes a POE::Filter::Grep object's behavior at run-time. It accepts the same parameters as \fBnew()\fR, and it replaces the existing tests with new ones. .PP .Vb 5 \& # Don\*(Aqt give away our Dialgas. \& $gotta_catch_nearly_all\->modify( \& Get => sub { 1 }, \& Put => sub { return shift() ne "dialga" }, \& ); .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" POE::Filter for more information about filters in general. .PP POE::Filter::Stackable for more details on stacking filters. .SH "BUGS" .IX Header "BUGS" None known. .SH "AUTHORS & COPYRIGHTS" .IX Header "AUTHORS & COPYRIGHTS" The Grep filter was contributed by Dieter Pearcey. Documentation is provided by Rocco Caputo. .PP Please see the \s-1POE\s0 manpage for more information about authors and contributors.