| 1 | package IO::Buffered::HTTP; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use base ("IO::Buffered"); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | # FIXME: Write documentation | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 9 | our $VERSION = '1.00'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | IO::Buffered::HTTP - HTTP buffering | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 9 | ▶ | use base "Exporter"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 9 | our @EXPORT_OK = qw(); | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | =item new() | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=22.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | my ($class, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | croak "Option MaxSize should be a positiv integer" if $opts{MaxSize} and !( | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | ▶ | $opts{MaxSize} =~ /^\d+$/ and $opts{MaxSize} > 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
$opts{"MaxSize"} and not $opts{"MaxSize"} =~ /^\d+$/ && $opts{"MaxSize"} > 0
$opts{'MaxSize'} =~ /^\d+$/ && $opts{'MaxSize'} > 0
MC/DC0%0/3
$opts{"MaxSize"} and not $opts{"MaxSize"} =~ /^\d+$/ && $opts{"MaxSize"} > 0
$opts{"MaxSize"}
$opts{'MaxSize'} =~ /^\d+$/
$opts{'MaxSize'} > 0
Truth table25%1/4
A and not(B && C)
A= $opts{"MaxSize"}B= $opts{'MaxSize'} =~ /^\d+$/C= $opts{'MaxSize'} > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | my %self = ( | ||||||||||||||||||||||||||||||||||||||||||
| 41 | maxsize => $opts{MaxSize}, | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | ▶ | headeronly => (exists $opts{HeaderOnly} ? $opts{HeaderOnly} : 0), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | buffer => '', | ||||||||||||||||||||||||||||||||||||||||||
| 44 | length => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 2 | ▶ | return bless \%self, (ref $class || $class); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | =item flush($str, ...) | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub flush { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flush: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | $self->{buffer} = join ('', @_); | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | =item buffer() | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub buffer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
buffer: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | return $self->{buffer}; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | =item write($str, ...) | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 5 | ▶ | sub write { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=3 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 5 | my $str = join ('', @_); | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 5 | ▶ | if(my $maxsize = $self->{maxsize}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $length = length($str) + length($self->{buffer}); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if($length > $maxsize) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | croak "Buffer overrun"; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 5 | $self->{buffer} .= $str; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | =item read() | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 7 | ▶ | sub read { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=13 SCAR=25.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 7 | my ($self, $readlength) = (@_); | |||||||||||||||||||||||||||||||||||||||||
| 92 | 7 | my @records; | |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | # FIXME: Something is boaken | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 7 | ▶ | $self->{length} = ($readlength or -1) if $self->{length} < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$readlength || -1
MC/DC0%0/1
$readlength || -1
$readlength
Truth table50%1/2
A
A= $readlength
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | #print "hello: $self->{length}, $readlength\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 7 | ▶ | while($self->{length} >= 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 9 | ▶ | if(my $length = $self->{length}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | ▶ | if(length $self->{buffer} >= $length) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 2 | push(@records, substr($self->{buffer}, 0, $length)); | |||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | substr($self->{buffer}, 0, $length) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 2 | $self->{length} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 105 | #$readlength = undef; | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 2 | ▶ | next if length($self->{buffer}) > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 7 | my $idx = index($self->{buffer}, "\r\n\r\n"); | |||||||||||||||||||||||||||||||||||||||||
| 111 | # Found what could be a header | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 7 | ▶ | if($idx >= 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 5 | my $header = substr($self->{buffer}, 0, $idx + 4);; | |||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 5 | ▶ | if($self->{headeronly}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | push(@records, $header); | |||||||||||||||||||||||||||||||||||||||||
| 117 | 2 | substr($self->{buffer}, 0, $idx + 4) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 2 | $self->{length} = -1; | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | } elsif($header =~ /Content-Length:\s+(\d+)/six) { | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 2 | my $length = $1 + $idx + 4; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 2 | ▶ | if(length $self->{buffer} >= $length) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 2 | push(@records, substr($self->{buffer}, 0, $length)); | |||||||||||||||||||||||||||||||||||||||||
| 124 | 2 | substr($self->{buffer}, 0, $length) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 2 | ▶ | next if length($self->{buffer}) > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $self->{length} = $length; | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | push(@records, $header); | |||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | substr($self->{buffer}, 0, $idx + 4) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | ▶ | next if length($self->{buffer}) > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 7 | last; | |||||||||||||||||||||||||||||||||||||||||
| 139 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 7 | return @records; | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | =item returns_last() | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | sub returns_last { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
returns_last: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | =item read_last() | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | ▶ | sub read_last { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_last: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | my @results = $self->read(); | |||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | ▶ | push(@results, $self->{buffer}) if $self->{buffer} ne ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 1 | $self->{buffer} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 1 | return @results; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | Troels Liebe Bentsen <tlb@rapanden.dk> | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | Copyright(C) 2008 Troels Liebe Bentsen | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 175 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||