1package HTTP::Proxy::BodyFilter::tags; 2 3use strict; 4use Carp; 5use HTTP::Proxy::BodyFilter; 6use vars qw( @ISA ); 7@ISA = qw( HTTP::Proxy::BodyFilter ); 8 9sub filter { 10 my ( $self, $dataref, $message, $protocol, $buffer ) = @_; 11 return if not defined $buffer; # last "tags" 12 13 my $idx = rindex( $$dataref, '<' ); 14 if ( $idx > rindex( $$dataref, '>' ) ) { 15 $$buffer = substr( $$dataref, $idx ); 16 $$dataref = substr( $$dataref, 0, $idx ); 17 } 18} 19 20sub will_modify { 0 } 21 221; 23 24__END__ 25 26=head1 NAME 27 28HTTP::Proxy::BodyFilter::tags - A filter that outputs only complete tags 29 30=head1 SYNOPSIS 31 32 use HTTP::Proxy::BodyFilter::tags; 33 use MyFilter; # this filter only works on complete tags 34 35 my $filter = MyFilter->new(); 36 37 # note that both filters will be run on the same messages 38 # (those with a MIME type of text/html) 39 $proxy->push_filter( 40 mime => 'text/*', 41 response => HTTP::Proxy::BodyFilter::tags->new 42 ); 43 $proxy->push_filter( mime => 'text/html', response => $filter ); 44 45=head1 DESCRIPTION 46 47The L<HTTP::Proxy::BodyFilter::tags> filter makes sure that the next filter 48in the filter chain will only receive complete tags. 49 50=head1 METHOD 51 52This class defines two methods, that are called automatically: 53 54=over 4 55 56=item filter() 57 58Buffer incomplete tags to ensure that subsequent filters will only 59receive complete HTML tags. 60 61=item will_modify() 62 63This method returns a I<false> value, thus indicating to the system 64that it will not modify data passing through. 65 66=back 67 68=head1 SEE ALSO 69 70L<HTTP::Proxy>, L<HTTP::Proxy::BodyFilter>. 71 72=head1 AUTHOR 73 74Philippe "BooK" Bruhat, E<lt>book@cpan.orgE<gt>. 75 76=head1 COPYRIGHT 77 78Copyright 2003-2013, Philippe Bruhat. 79 80=head1 LICENSE 81 82This module is free software; you can redistribute it or modify it under 83the same terms as Perl itself. 84 85=cut 86 87