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.304';
3 3     3   17270 use strict;
  3         5  
  3         92  
4 3     3   10 use Carp;
  3         5  
  3         160  
5 3     3   364 use HTTP::Proxy::BodyFilter;
  3         4  
  3         55  
6 3     3   10 use vars qw( @ISA );
  3         4  
  3         974  
7             @ISA = qw( HTTP::Proxy::BodyFilter );
8              
9             sub init {
10 8     8 1 7 my $self = shift;
11              
12 8 100 100     276 croak "slurp mode is not supported. Use HTTP::Proxy::BodyFilter::store."
13             if @_ && not defined $_[0];
14              
15 7 100       14 my $eol = @_ ? $_[0] : "\n"; # FIXME shouldn't this be $/?
16 7 100       15 if ( ref $eol eq 'SCALAR' ) {
17 3         8 local $^W;
18 3 100       129 croak qq'"$$eol" is not numeric' if $$eol ne ( 0 + $$eol );
19 2 100       104 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 7807 my ( $self, $dataref, $message, $protocol, $buffer ) = @_;
26 15 100       34 return if not defined $buffer; # last "lines"
27              
28 11         18 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         9 $$dataref =~ /^(.*\n\n)([^\n].*)/sg;
33 2 100       13 ( $$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         5 $$buffer = substr( $$dataref, $idx );
38 2         6 $$dataref = substr( $$dataref, 0, $idx );
39             }
40             else {
41 7         13 my $idx = rindex( $$dataref, $eol );
42 7 100       12 if ( $idx == -1 ) {
43 1         2 $$buffer = $$dataref; # keep everything for later
44 1         2 $$dataref = '';
45             }
46             else {
47 6         12 $idx += length($eol);
48 6         11 $$buffer = substr( $$dataref, $idx );
49 6         12 $$dataref = substr( $$dataref, 0, $idx );
50             }
51             }
52             }
53              
54 1     1 1 3 sub will_modify { 0 }
55              
56             1;
57              
58             __END__