HTTP::...:simple(3pm)
π HTTP::Proxy::BodyFilter::simple β the manual page, bestie edition π
okay so like, this page lives in the User Contributed Perl Documentation section, it's HTTP::...:simple(3pm), and the module's actual full name is HTTP::Proxy::BodyFilter::simple. yes the header truncates it, no that's not my fault, it's giving β¨abbreviatedβ¨. anyway. sit down. hydrate. let's go π«Ά
πΈ NAME πΈ
HTTP::Proxy::BodyFilter::simple β a class for creating simple filters π
β¨ SYNOPSIS β¨
use HTTP::Proxy::BodyFilter::simple;
# a simple s/// filter
my $filter = HTTP::Proxy::BodyFilter::simple->new(
sub { ${ $_[1] } =~ s/foo/bar/g; }
);
$proxy->push_filter( response => $filter );
look at that. three lines and you have a whole filter. no class, no boilerplate, no 400-line package declaration, we simply do not have the time π
π¦ DESCRIPTION π¦
HTTP::Proxy::BodyFilter::simple lets you build a BodyFilter without going through the whole hassle of creating a full-fledged class. that's the entire personality. you just hand a code reference to the filter() method of your filter over to the constructor, and boom β you get the adequate filter. no cap, that's it, that's the deal π
π Constructor calling convention π
the constructor is flexible like that, and it can be called several ways β all of which are shown in the synopsis. pick your fighter:
- single code reference β the code reference has to conform to the standard
filter()signature:
sub filter {
my ( $self, $dataref, $message, $protocol, $buffer ) = @_;
...
}
it's assumed to be the code for the filter() method. wanna know more about the filter() method? go read HTTP::Proxy::BodyFilter, it has all the details π
- name/coderef pairs β the name is the name of the method (
filter,begin,end) and the coderef is the method itself. for the methods' signatures, again:HTTP::Proxy::BodyFilter. iykyk π
π METHODS π
so this filter "factory" defines the standard HTTP::Proxy::BodyFilter methods β but those are only, erm, "proxies" to the actual CODE references you passed to the constructor. that's right, they're middlemen. agents. little guys doing forwarding. these "proxy" methods are:
filter()begin()end()
then there are two other methods that are actually HTTP::Proxy::BodyFilter::simple methods, and they get called automatically:
init()β initialises the filter instance with the code references that were passed to the constructor.can()β returns the actual code reference that will be run, and not the "proxy" methods. but wait, plot twist: if it's called with any other name thanbegin,endandfilter, it callsUNIVERSAL::can()instead. versatile π
and there's also a method that returns a boolean value:
will_modify()β returns a scalar value (boolean) indicating if the filter may modify the body data. the default method returns a true value, so you only need to set this value when you are absolutely certain that the filter will not modify data (or at least not modify its final length).
here's a simple example, look how cute:
$filter = HTTP::Proxy::BodyFilter::simple->new(
filter => sub { ${ $_[1] } =~ s/foo/bar/g; },
will_modify => 0, # "foo" is the same length as "bar"
);
note that the comment is doing the heavy lifting there:"foo"is the same length as"bar", which is exactly whywill_modify => 0is allowed to be true-to-its-word here. length-preserving swaps only, bestie π
π SEE ALSO π
HTTP::ProxyHTTP::Proxy::BodyFilter
π AUTHOR π
Philippe "BooK" Bruhat, <book@cpan.org>.
π COPYRIGHT π
Copyright 2003-2015, Philippe Bruhat.
π LICENSE π
This module is free software; you can redistribute it or modify it under the same terms as Perl itself.
and that's the whole page, you ate that π«Ά this was HTTP::...:simple(3pm) from perl v5.36.0, dated 2022-12-04, served up fresh from the User Contributed Perl Documentation archives. go write a filter, main character β¨π
π¦ where this page comes from
- debian bookworm: libhttp-proxy-perl 0.304-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libhttp-proxy-perl 0.304-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libhttp-proxy-perl 0.304-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms