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.304';
3 4     4   17367 use strict;
  4         6  
  4         135  
4 4     4   16 use Carp;
  4         4  
  4         242  
5 4     4   539 use HTTP::Proxy::BodyFilter;
  4         15  
  4         103  
6 4     4   20 use vars qw( @ISA );
  4         5  
  4         1930  
7             @ISA = qw( HTTP::Proxy::BodyFilter );
8              
9             sub init {
10 3 50   3 1 13 croak "Parameter must be a CODE reference" unless ref $_[1] eq 'CODE';
11 3         20 $_[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 20 my ( $self, $dataref, $message, $protocol, $buffer ) = @_;
18              
19 6         18 my $pos = pos($$dataref) = 0;
20 66         57 SCAN:
21             {
22 6         9 $pos = pos($$dataref);
23             $$dataref =~ /\G<\s*(?:script|style)[^>]*>/cgi # protect
24 66 50       172 && do { $self->{js} = 1; redo SCAN; };
  0         0  
  0         0  
25             $$dataref =~ /\G<\s*\/\s*(?:script|style)[^>]*>/cgi # unprotect
26 66 100       119 && 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       88 $$dataref =~ /\G