| 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
| |||||||||||
| 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
| |||||||||||
| 25 | $$dataref =~ /\G<\s*\/\s*(?:script|style)[^>]*>/cgi # unprotect | ||||||||||
| 26 | 66 | ▶ | && do { $self->{js} = 0; redo SCAN; }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 31 | 65 | ▶ | $$dataref =~ /\G>/cg && redo SCAN; # lost > | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 65 | ▶ | $$dataref =~ /\G(?=(<[^\s\/?%!a-z]))/cgi && goto TEXT; # < in text | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 63 | ▶ | $$dataref =~ /\G(?:<[^>]*>)+/cg && redo SCAN; # tags | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 37 | ▶ | $$dataref =~ /\G(?:&[^\s;]*;?)+/cg && redo SCAN; # entities | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 35 | ▶ | $$dataref =~ /\G([^<>&]+)/cg && goto TEXT; # text | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 6 | last SCAN; | |||||||||
| 37 | TEXT: | ||||||||||
| 38 | 31 | ▶ | redo SCAN if $self->{js}; # ignore protected | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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__ | ||||||||||