| 1 | package HTTP::Proxy::BodyFilter::lines; | ||||||||||||||||||||||||||||
| 2 | 3 | $HTTP::Proxy::BodyFilter::lines::VERSION = '0.304'; | |||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use HTTP::Proxy::BodyFilter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use vars qw( @ISA ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | @ISA = qw( HTTP::Proxy::BodyFilter ); | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 8 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 10 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 8 | ▶ | croak "slurp mode is not supported. Use HTTP::Proxy::BodyFilter::store." | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ and not defined $_[0]
MC/DC100%2/2
@_ and not defined $_[0]
@_
not defined $_[0]
Truth table100%3/3
A and not(B)
A= @_B= not defined $_[0]
| |||||||||||||||||||||||||||||
| 13 | if @_ && not defined $_[0]; | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 7 | ▶ | my $eol = @_ ? $_[0] : "\n"; # FIXME shouldn't this be $/? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 7 | ▶ | if ( ref $eol eq 'SCALAR' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | 3 | local $^W; | |||||||||||||||||||||||||||
| 18 | 3 | ▶ | croak qq'"$$eol" is not numeric' if $$eol ne ( 0 + $$eol ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | croak "Records of size 0 are not supported" if $$eol == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | 5 | $self->{eol} = $eol; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 15 | ▶ | sub filter { | ||||||||||||||||||||||||||
|
Subroutine
filter: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 15 | my ( $self, $dataref, $message, $protocol, $buffer ) = @_; | |||||||||||||||||||||||||||
| 26 | 15 | ▶ | return if not defined $buffer; # last "lines" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 11 | my $eol = $self->{eol}; | |||||||||||||||||||||||||||
| 29 | 11 | ▶ | if ( $eol eq "" ) { # paragraph mode | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 30 | # if $$dataref ends with \n\n, we cannot know if there are | ||||||||||||||||||||||||||||
| 31 | # more white lines at the beginning of the next chunk of data | ||||||||||||||||||||||||||||
| 32 | 2 | $$dataref =~ /^(.*\n\n)([^\n].*)/sg; | |||||||||||||||||||||||||||
| 33 | 2 | ▶ | ( $$dataref, $$buffer) = defined $1 ? ($1, $2) : ("", $$dataref); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | elsif ( ref $eol eq 'SCALAR' ) { # record mode | ||||||||||||||||||||||||||||
| 36 | 2 | my $idx = length($$dataref) - length($$dataref) % $$eol; | |||||||||||||||||||||||||||
| 37 | 2 | $$buffer = substr( $$dataref, $idx ); | |||||||||||||||||||||||||||
| 38 | 2 | $$dataref = substr( $$dataref, 0, $idx ); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | else { | ||||||||||||||||||||||||||||
| 41 | 7 | my $idx = rindex( $$dataref, $eol ); | |||||||||||||||||||||||||||
| 42 | 7 | ▶ | if ( $idx == -1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 1 | $$buffer = $$dataref; # keep everything for later | |||||||||||||||||||||||||||
| 44 | 1 | $$dataref = ''; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | else { | ||||||||||||||||||||||||||||
| 47 | 6 | $idx += length($eol); | |||||||||||||||||||||||||||
| 48 | 6 | $$buffer = substr( $$dataref, $idx ); | |||||||||||||||||||||||||||
| 49 | 6 | $$dataref = substr( $$dataref, 0, $idx ); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | ▶ | sub will_modify { 0 } | ||||||||||||||||||||||||||
|
Subroutine
will_modify: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 3 | 1; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | __END__ | ||||||||||||||||||||||||||||