File Coverage

blib/lib/HTTP/Proxy/BodyFilter/lines.pm
Criterion Covered Total %
statement 37 37 100.0
branch 20 20 100.0
condition 3 3 100.0
subroutine 7 7 100.0
pod 3 3 100.0
total 70 70 100.0


line stmt bran cond sub pod time code
1             package HTTP::Proxy::BodyFilter::lines;
2             $HTTP::Proxy::BodyFilter::lines::VERSION = '0.302';
3 3     3   17460 use strict;
  3         4  
  3         86  
4 3     3   12 use Carp;
  3         3  
  3         185  
5 3     3   347 use HTTP::Proxy::BodyFilter;
  3         3  
  3         55  
6 3     3   10 use vars qw( @ISA );
  3         4  
  3         1003  
7             @ISA = qw( HTTP::Proxy::BodyFilter );
8              
9             sub init {
10 8     8 1 9 my $self = shift;
11              
12 8 100 100     223 croak "slurp mode is not supported. Use HTTP::Proxy::BodyFilter::store."
13             if @_ && not defined $_[0];
14              
15 7 100       15 my $eol = @_ ? $_[0] : "\n"; # FIXME shouldn't this be $/?
16 7 100       16 if ( ref $eol eq 'SCALAR' ) {
17 3         8 local $^W;
18 3 100       134 croak qq'"$$eol" is not numeric' if $$eol ne ( 0 + $$eol );
19 2 100       109 croak "Records of size 0 are not supported" if $$eol == 0;
20             }
21 5         20 $self->{eol} = $eol;
22             }
23              
24             sub filter {
25 15     15 1 11158 my ( $self, $dataref, $message, $protocol, $buffer ) = @_;
26 15 100       36 return if not defined $buffer; # last "lines"
27              
28 11         14 my $eol = $self->{eol};
29 11 100       28 if ( $eol eq "" ) { # paragraph mode
    100          
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         8 $$dataref =~ /^(.*\n\n)([^\n].*)/sg;
33 2 100       12 ( $$dataref, $$buffer) = defined $1 ? ($1, $2) : ("", $$dataref);
34             }
35             elsif ( ref $eol eq 'SCALAR' ) { # record mode
36 2         6 my $idx = length($$dataref) - length($$dataref) % $$eol;
37 2         3 $$buffer = substr( $$dataref, $idx );
38 2         6 $$dataref = substr( $$dataref, 0, $idx );
39             }
40             else {
41 7         10 my $idx = rindex( $$dataref, $eol );
42 7 100       11 if ( $idx == -1 ) {
43 1         3 $$buffer = $$dataref; # keep everything for later
44 1         3 $$dataref = '';
45             }
46             else {
47 6         9 $idx += length($eol);
48 6         8 $$buffer = substr( $$dataref, $idx );
49 6         14 $$dataref = substr( $$dataref, 0, $idx );
50             }
51             }
52             }
53              
54 1     1 1 3 sub will_modify { 0 }
55              
56             1;
57              
58             __END__