WARC/Record/Payload.pm

filter: Statementstmt 98.1% 54 / 55 Branchbran 90.0% 8 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 16 / 16 Podpod n/a totaltotal 97.5% 78 / 81 CC 6 SCAR 5.7
CC
6
Cov
97%
TIEHANDLE
4.0
READ
2.0
SEEK
2.0
CRAP 1.8
« WARC/Record/Replay/HTTP/Request.pm ↑ Summary WARC/Index/Entries.pm »
1 package WARC::Record::Payload; # -*- CPerl -*-
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use WARC; *WARC::Record::Payload::VERSION = \$WARC::VERSION;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Fcntl qw/SEEK_SET SEEK_CUR SEEK_END/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # This implementation uses an array as the underlying object.
12  
13 1 ▶use constant { BASE => 0, HANDLE => 1, PARENT => 2 };
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use constant OBJECT_INIT => undef, undef, undef;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 sub _dbg_dump {
17 8 ▶ my $self = shift;
Subroutine _dbg_dump: called CC=1 SCAR=0.0
18  
19 8 my $out = 'record payload @'.(tell $self->[HANDLE]);
20 8 $out .= "\n";
21  
22 8 return $out;
23 }
24  
25 sub TIEHANDLE {
26 8 ▶ my $class = shift;
Subroutine TIEHANDLE: called CC=4 SCAR=13.9
27 8 my $parent = shift;
28 8 my $replay = shift;
29  
30 # The payload_offset key will be set in $parent iff loading was deferred.
31 8 my $handle; my $base_offset;
32 8 ▶ if (defined $parent->{payload_offset}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $parent->{'payload_offset'}) { } 4 4 8
elsif ($replay->can('content_ref')) { } 4 0 4
33 4 $handle = $parent->open_continued;
34 4 $base_offset = $parent->{payload_offset};
35 } elsif ($replay->can('content_ref')) {
36 # The payload was smaller than the deferred loading threshold.
37 # This open fails iff perl was built without PerlIO, which is non-default.
38 # uncoverable branch true
39 4 ▶ open $handle, '<', $replay->content_ref
Branch: 1 branch
BranchTrueFalseTotal
open $handle, "<", $replay->content_ref or die "failure opening stream on replay object buffer: $!" 0 4 4
40 or die "failure opening stream on replay object buffer: $!";
41 4 binmode $handle, ':raw';
42 4 $base_offset = 0;
43 } else
44 0 { confess 'extracting payload from '.(ref $replay).' not implemented' }
45  
46 8 my $ob = [OBJECT_INIT];
47 8 @$ob[PARENT, HANDLE, BASE] = ($parent, $handle, $base_offset);
48  
49 8 bless $ob, $class;
50  
51 8 $ob->SEEK(0, SEEK_SET);
52  
53 8 return $ob;
54 }
55  
56 # TODO: implement payload decoding
57  
58 12 ▶sub READLINE { readline $_[0]->[HANDLE] }
Subroutine READLINE: called CC=1 SCAR=0.0
59  
60 # This sub must rely on the aliasing effect of @_.
61 4 ▶sub READ { read $_[0]->[HANDLE], $_[1], $_[2], (defined $_[3] ? $_[3] : 0) }
Subroutine READ: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[3] ? : 2 2 4
62  
63 18 ▶sub GETC { getc $_[0]->[HANDLE] }
Subroutine GETC: called CC=1 SCAR=0.0
64  
65 8 ▶sub EOF { eof $_[0]->[HANDLE] }
Subroutine EOF: called CC=1 SCAR=0.0
66  
67 sub SEEK {
68 12 ▶ my $self = shift;
Subroutine SEEK: called CC=2 SCAR=6.9
69 12 my $offset = shift;
70 12 my $whence = shift;
71  
72 12 my $adjust = 0;
73 12 ▶ $adjust = $self->[BASE] if $whence == SEEK_SET;
Branch: 1 branch
BranchTrueFalseTotal
if $whence == 0 10 2 12
74  
75 12 seek $self->[HANDLE], $adjust + $offset, $whence
76 }
77  
78 4 ▶sub TELL { return ((tell $_[0]->[HANDLE]) - $_[0]->[BASE]) }
Subroutine TELL: called CC=1 SCAR=0.0
79  
80 2 ▶sub CLOSE { close $_[0]->[HANDLE] }
Subroutine CLOSE: called CC=1 SCAR=0.0
81  
82 1 1;
83 __END__
« WARC/Record/Replay/HTTP/Request.pm ↑ Summary WARC/Index/Entries.pm »