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