HTTP::...:simple(3pm)

πŸ“¦
version 0.304 Β· 5 versions
, in debian bookworm, debian trixie, ubuntu noble

πŸ’– 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 than begin, end and filter, it calls UNIVERSAL::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 why will_modify => 0 is allowed to be true-to-its-word here. length-preserving swaps only, bestie πŸ“

🌟 SEE ALSO 🌟

  • HTTP::Proxy
  • HTTP::Proxy::BodyFilter

πŸ’œ AUTHOR πŸ’œ

Philippe "BooK" Bruhat, <book@cpan.org>.


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