package HTTP::Proxy::BodyFilter::htmltext; use strict; use Carp; use HTTP::Proxy::BodyFilter; use vars qw( @ISA ); @ISA = qw( HTTP::Proxy::BodyFilter ); sub init { croak "Parameter must be a CODE reference" unless ref $_[1] eq 'CODE'; $_[0]->{_filter} = $_[1]; } sub begin { $_[0]->{js} = 0; } # per message initialisation sub filter { my ( $self, $dataref, $message, $protocol, $buffer ) = @_; my $pos = pos($$dataref) = 0; SCAN: { $pos = pos($$dataref); $$dataref =~ /\G<\s*(?:script|style)[^>]*>/cgi # protect && do { $self->{js} = 1; redo SCAN; }; $$dataref =~ /\G<\s*\/\s*(?:script|style)[^>]*>/cgi # unprotect && do { $self->{js} = 0; redo SCAN; }; # comments are considered as text # if you want comments as comments, # use HTTP::Proxy::BodyFilter::htmlparser $$dataref =~ /\G