Proxy/BodyFilter/htmltext.pm

filter: Statementstmt 95.2% 40 / 42 Branchbran 75.0% 15 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 90.2% 65 / 72 CC 11 SCAR 18.9
CC
11
Cov
89%
filter
10.3
init
2.1
BEGIN
1.0
CRAP 6.6
« Proxy/HeaderFilter/simple.pm ↑ Summary Proxy/Engine/Legacy.pm »
1 package HTTP::Proxy::BodyFilter::htmltext;
2 4 $HTTP::Proxy::BodyFilter::htmltext::VERSION = '0.304';
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use HTTP::Proxy::BodyFilter;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 @ISA = qw( HTTP::Proxy::BodyFilter );
8  
9 3 ▶sub init {
Subroutine init: called CC=2 SCAR=7.2
Pod documented
10 3 ▶ croak "Parameter must be a CODE reference" unless ref $_[1] eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[1] eq "CODE" 0 3 3
11 3 $_[0]->{_filter} = $_[1];
12 }
13  
14 1 ▶sub begin { $_[0]->{js} = 0; } # per message initialisation
Subroutine begin: called CC=1 SCAR=0.0
Pod documented
15  
16 6 ▶sub filter {
Subroutine filter: called CC=10 SCAR=23.3
Pod documented
17 6 my ( $self, $dataref, $message, $protocol, $buffer ) = @_;
18  
19 6 my $pos = pos($$dataref) = 0;
20 SCAN:
21 {
22 6 $pos = pos($$dataref);
23 $$dataref =~ /\G<\s*(?:script|style)[^>]*>/cgi # protect
24 0 ▶ && do { $self->{js} = 1; redo SCAN; };
Branch: 1 branch
BranchTrueFalseTotal
$$dataref =~ /\G<\s*(?:script|style)[^>]*>/cig and do { $self->{"js"} = 1; redo SCAN } 0 66 66
25 $$dataref =~ /\G<\s*\/\s*(?:script|style)[^>]*>/cgi # unprotect
26 66 ▶ && do { $self->{js} = 0; redo SCAN; };
Branch: 1 branch
BranchTrueFalseTotal
$$dataref =~ m[\G<\s*/\s*(?:script|style)[^>]*>]cig and do { $self->{"js"} = 0; redo SCAN } 1 65 66
27 # comments are considered as text
28 # if you want comments as comments,
29 # use HTTP::Proxy::BodyFilter::htmlparser
30 65 ▶ $$dataref =~ /\G<!--/cg && redo SCAN; # comment
Branch: 1 branch
BranchTrueFalseTotal
$$dataref =~ /\G<!--/cg and redo SCAN 0 65 65
31 65 ▶ $$dataref =~ /\G>/cg && redo SCAN; # lost >
Branch: 1 branch
BranchTrueFalseTotal
$$dataref =~ /\G>/cg and redo SCAN 0 65 65
32 65 ▶ $$dataref =~ /\G(?=(<[^\s\/?%!a-z]))/cgi && goto TEXT; # < in text
Branch: 1 branch
BranchTrueFalseTotal
$$dataref =~ m[\G(?=(<[^\s/?%!a-z]))]cig and goto TEXT 2 63 65
33 63 ▶ $$dataref =~ /\G(?:<[^>]*>)+/cg && redo SCAN; # tags
Branch: 1 branch
BranchTrueFalseTotal
$$dataref =~ /\G(?:<[^>]*>)+/cg and redo SCAN 26 37 63
34 37 ▶ $$dataref =~ /\G(?:&[^\s;]*;?)+/cg && redo SCAN; # entities
Branch: 1 branch
BranchTrueFalseTotal
$$dataref =~ /\G(?:&[^\s;]*;?)+/cg and redo SCAN 2 35 37
35 35 ▶ $$dataref =~ /\G([^<>&]+)/cg && goto TEXT; # text
Branch: 1 branch
BranchTrueFalseTotal
$$dataref =~ /\G([^<>&]+)/cg and goto TEXT 29 6 35
36 6 last SCAN;
37 TEXT:
38 31 ▶ redo SCAN if $self->{js}; # ignore protected
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"js"} 0 31 31
39 {
40 31 local $_ = $1;
41 31 $self->{_filter}->();
42 31 substr( $$dataref, $pos, length($1), $_ );
43 31 pos($$dataref) = $pos + length($_);
44 }
45 31 redo SCAN;
46 }
47 }
48  
49 4 1;
50  
51 __END__
« Proxy/HeaderFilter/simple.pm ↑ Summary Proxy/Engine/Legacy.pm »