File Coverage

blib/lib/HTTP/Proxy/BodyFilter/htmltext.pm
Criterion Covered Total %
statement 37 39 94.8
branch 15 20 75.0
condition n/a
subroutine 7 7 100.0
pod 3 3 100.0
total 62 69 89.8


line stmt bran cond sub pod time code
1             package HTTP::Proxy::BodyFilter::htmltext;
2             $HTTP::Proxy::BodyFilter::htmltext::VERSION = '0.303';
3 4     4   14251 use strict;
  4         4  
  4         97  
4 4     4   13 use Carp;
  4         4  
  4         170  
5 4     4   300 use HTTP::Proxy::BodyFilter;
  4         4  
  4         69  
6 4     4   12 use vars qw( @ISA );
  4         4  
  4         1347  
7             @ISA = qw( HTTP::Proxy::BodyFilter );
8              
9             sub init {
10 3 50   3 1 10 croak "Parameter must be a CODE reference" unless ref $_[1] eq 'CODE';
11 3         14 $_[0]->{_filter} = $_[1];
12             }
13              
14 1     1 1 4 sub begin { $_[0]->{js} = 0; } # per message initialisation
15              
16             sub filter {
17 6     6 1 17 my ( $self, $dataref, $message, $protocol, $buffer ) = @_;
18              
19 6         17 my $pos = pos($$dataref) = 0;
20 66         52 SCAN:
21             {
22 6         6 $pos = pos($$dataref);
23             $$dataref =~ /\G<\s*(?:script|style)[^>]*>/cgi # protect
24 66 50       141 && do { $self->{js} = 1; redo SCAN; };
  0         0  
  0         0  
25             $$dataref =~ /\G<\s*\/\s*(?:script|style)[^>]*>/cgi # unprotect
26 66 100       105 && do { $self->{js} = 0; redo SCAN; };
  1         3  
  1         1  
27             # comments are considered as text
28             # if you want comments as comments,
29             # use HTTP::Proxy::BodyFilter::htmlparser
30 65 50       82 $$dataref =~ /\G