1HTTP::Proxy::BodyFilterU:s:esrimCpolnet(r3i)buted Perl DHoTcTuPm:e:nPtraotxiyo:n:BodyFilter::simple(3)
2
3
4
6 HTTP::Proxy::BodyFilter::simple - A class for creating simple filters
7
9 use HTTP::Proxy::BodyFilter::simple;
10
11 # a simple s/// filter
12 my $filter = HTTP::Proxy::BodyFilter::simple->new(
13 sub { ${ $_[1] } =~ s/foo/bar/g; }
14 );
15 $proxy->push_filter( response => $filter );
16
18 HTTP::Proxy::BodyFilter::simple can create BodyFilter without going
19 through the hassle of creating a full-fledged class. Simply pass a code
20 reference to the "filter()" method of your filter to the constructor,
21 and you'll get the adequate filter.
22
23 Constructor calling convention
24
25 The constructor can be called in several ways, which are shown in the
26 synopsis:
27
28 single code reference
29 The code reference must conform to the standard filter() signature:
30
31 sub filter {
32 my ( $self, $dataref, $message, $protocol, $buffer ) = @_;
33 ...
34 }
35
36 It is assumed to be the code for the "filter()" method. See
37 HTTP::Proxy::BodyFilter.pm for more details about the "filter()"
38 method.
39
40 name/coderef pairs
41 The name is the name of the method ("filter", "begin", "end") and
42 the coderef is the method itself.
43
44 See HTTP::Proxy::BodyFilter for the methods signatures.
45
47 This filter "factory" defines the standard HTTP::Proxy::BodyFilter
48 methods, but those are only, erm, "proxies" to the actual CODE refer‐
49 ences passed to the constructor. These "proxy" methods are:
50
51 filter()
52 begin()
53 end()
54
55 Two other methods are actually HTTP::Proxy::BodyFilter::simple methods,
56 and are called automatically:
57
58 init()
59 Initalise the filter instance with the code references passed to
60 the constructor.
61
62 can()
63 Return the actual code reference that will be run, and not the
64 "proxy" methods. If called with any other name than "begin", "end"
65 and "filter", calls UNIVERSAL::can() instead.
66
67 There is also a method that returns a boolean value:
68
69 will_modify()
70 The "will_modify()" method returns a scalar value (boolean) indi‐
71 cating if the filter may modify the body data. The default method
72 returns a true value, so you only need to set this value when you
73 are absolutely certain that the filter will not modify data (or at
74 least not modify its final length).
75
76 Here's a simple example:
77
78 $filter = HTTP::Proxy::BodyFilter::simple->new(
79 filter => sub { ${ $_[1] } =~ s/foo/bar/g; },
80 will_modify => 0, # "foo" is the same length as "bar"
81 );
82
84 HTTP::Proxy, HTTP::Proxy::BodyFilter.
85
87 Philippe "BooK" Bruhat, <book@cpan.org>.
88
90 Copyright 2003-2006, Philippe Bruhat.
91
93 This module is free software; you can redistribute it or modify it
94 under the same terms as Perl itself.
95
96
97
98perl v5.8.8 2006-09-04HTTP::Proxy::BodyFilter::simple(3)