Dumpfile/Node/Headers.pm

filter: Statementstmt 68.3% 67 / 98 Branchbran 55.7% 29 / 52 Conditioncond 37.5% 18 / 48 MC/DCmcdc 11.5% 3 / 26 Subroutinesub 100% 10 / 10 Podpod 100% 6 / 6 totaltotal 55.4% 133 / 240 CC 45 SCAR 44.8
CC
45
Cov
58%
sanitycheck
188.7
new
11.3
read
10.6
CRAP 88.1
↑ Summary Dumpfile/Node.pm »
1 ################################################################################
2 # Copyright (c) 2008 Martin Scharrer <martin@scharrer-online.de>
3 # This is open source software under the GPL v3 or later.
4 #
5 # $Id: Headers.pm 103 2008-10-14 21:11:21Z martin $
6 ################################################################################
7 package SVN::Dumpfile::Node::Headers;
8 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 Readonly my $NL => chr(10);
13  
14 11 our $VERSION = do { '$Rev: 103 $' =~ /\$Rev: (\d+) \$/; '0.13' . ".$1" };
15  
16 11 my @SVNHEADER = qw(
17 Revision-number
18 Node-path
19 Node-kind
20 Node-action
21 Node-copyfrom-rev
22 Node-copyfrom-path
23 Prop-delta
24 Prop-content-length
25 Text-delta
26 Text-content-length
27 Text-copy-source-md5
28 Text-content-md5
29 Content-length
30 );
31  
32 43 ▶sub new {
Subroutine new: called CC=9 SCAR=24.2
Pod documented
33 43 my $class = shift;
34 43 my $self = {};
35  
36 43 ▶ if ( @_ == 1 && ref $_[0] eq 'HASH' ) {
Branch: 4 branches
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 3 40 43
elsif (@_ == 1 and ref $_[0] eq 'ARRAY' and @{$_[0];} % 2 == 0) { } 1 39 40
elsif (@_ % 2 == 0) { } 0 39 39
elsif (@_ == 1 and not defined $_[0]) { } 39 0 39
Condition66%2/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
0403
MC/DC50%1/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
37 3 $self = { %{ $_[0] } };
38 }
39 1 ▶ elsif ( @_ == 1 && ref $_[0] eq 'ARRAY' && @{ $_[0] } % 2 == 0 ) {
Condition66%4/6
@_ == 1 and ref $_[0] eq "ARRAY" and @{$_[0];} % 2 == 0
!ll&&!rl&&r
3901
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
0391
MC/DC33%1/3
@_ == 1 and ref $_[0] eq "ARRAY" and @{$_[0];} % 2 == 0
@_ == 1 ref $_[0] eq "ARRAY" @{$_[0];} % 2 == 0
Truth table50%2/4
A and B and C
A= @_ == 1B= ref $_[0] eq "ARRAY"C= @{$_[0];} % 2 == 0
ABCresult
0XX0
10X0
1100
1111
40 1 $self = { @{ $_[0] } };
41 }
42 elsif ( @_ % 2 == 0 ) {
43 0 $self = {@_};
44 }
45 ▶ elsif ( @_ == 1 && !defined $_[0] ) {
Condition33%1/3
@_ == 1 and not defined $_[0]
!ll&&!rl&&r
0039
MC/DC0%0/2
@_ == 1 and not defined $_[0]
@_ == 1 not defined $_[0]
Truth table33%1/3
A and not(B)
A= @_ == 1B= not defined $_[0]
ABresult
0X0
100
111
46  
47 # Ignore single undef value
48 }
49 else {
50 0 carp "${class}::new() awaits hashref, key/value pairs or an "
51 . "arrayref to them as arguments. Ignoring all arguments.";
52 0 return;
53 }
54 43 $self = bless $self, $class;
55 43 return $self;
56 }
57  
58 18 ▶sub number {
Subroutine number: called CC=1 SCAR=0.0
Pod documented
59 18 my $self = shift;
60 18 scalar keys %$self;
61 }
62  
63 29 ▶sub read {
Subroutine read: called CC=8 SCAR=23.6
Pod documented
64 29 my $self = shift;
65 29 my $fh = shift;
66  
67 29 my $line = eval { $fh->getline };
68 29 ▶ return unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 3 26 29
69  
70 26 ▶ while ( defined $line and $line =~ /^$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line and $line =~ /^$/) 0 26 26
Condition33%1/3
defined $line and $line =~ /^$/
!ll&&!rl&&r
0260
MC/DC0%0/2
defined $line and $line =~ /^$/
defined $line $line =~ /^$/
Truth table33%1/3
A and B
A= defined $lineB= $line =~ /^$/
ABresult
0X0
100
111
71 0 $line = $fh->getline;
72 }
73  
74 # Should be 'Node-path: ' or 'Revision-number: ' now
75 26 ▶ if ( $line !~ /^(Node-path|Revision-number): / ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line =~ /^(Node-path|Revision-number): /) 0 26 26
76 0 chomp($line);
77 0 croak "No node start found at input file position ", $fh->tell, ".";
78 }
79  
80 # Read headers
81 26 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
defined($line = $fh->getline) and not $line =~ /^$/ and do { do { if ($line =~ /^([^:]+):\s*(.*)$/) { $self->{$1} = $2; } else { chomp $line; croak("Error in header at position ", $fh->tell, ", input line '${line}'"); } } } 102 26 128
Condition66%2/3
defined($line = $fh->getline) and not $line =~ /^$/
!ll&&!rl&&r
026102
MC/DC50%1/2
defined($line = $fh->getline) and not $line =~ /^$/
defined($line = $fh->getline) not $line =~ /^$/
Truth table66%2/3
A and not(B)
A= defined($line = $fh->getline)B= not $line =~ /^$/
ABresult
0X0
100
111
82 128 ▶ if ( $line =~ /^([^:]+):\s*(.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^([^:]+):\s*(.*)$/) { } 128 0 128
83 128 $self->{$1} = $2;
84 }
85 else {
86 0 chomp $line;
87 0 croak "Error in header at position ", $fh->tell,
88 ", input line '$line'";
89 }
90 } while ( defined( $line = $fh->getline ) && $line !~ /^$/ );
91  
92 26 return 1;
93 }
94  
95 44 ▶sub as_string {
Subroutine as_string: called CC=4 SCAR=13.9
Pod documented
96 44 my $self = shift;
97 44 my $str = "";
98  
99 44 my %not_printed = map { $_ => 0 } keys %$self;
100  
101 # Print in given order
102 44 foreach my $key (@SVNHEADER) {
103 572 ▶ next unless exists $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$key} 358 214 572
104 214 $str .= "${key}: $self->{$key}$NL";
105 214 delete $not_printed{$key};
106 }
107  
108 # Print rest if exists
109 44 foreach my $key ( keys %not_printed ) {
110 0 $str .= "${key}: $self->{$key}$NL";
111 }
112 44 return $str;
113 }
114  
115 11 *to_string = \&as_string;
116  
117 18 ▶sub write {
Subroutine write: called CC=4 SCAR=16.6
Pod documented
118 18 my $self = shift;
119 18 my $fh = shift;
120  
121 18 ▶ unless ( eval { $fh->isa('IO::Handle') }
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $fh->isa("IO::Handle") } } or ref $fh eq "GLOB" or ref \$fh eq "GLOB") 0 18 18
Condition33%2/6
eval { do { $fh->isa("IO::Handle") } } or ref $fh eq "GLOB" or ref \$fh eq "GLOB"
l!l&&r!l&&!r
1800
eval { do { $fh->isa("IO::Handle") } } or ref $fh eq "GLOB"
l!l&&r!l&&!r
1800
MC/DC0%0/3
eval { do { $fh->isa("IO::Handle") } } or ref $fh eq "GLOB" or ref \$fh eq "GLOB"
eval { do { $fh->isa("IO::Handle") } } ref $fh eq "GLOB" ref \$fh eq "GLOB"
Truth table25%1/4
A or B or C
A= eval { do { $fh->isa("IO::Handle") } }B= ref $fh eq "GLOB"C= ref \$fh eq "GLOB"
ABCresult
1XX1
01X1
0011
0000
122 || ref $fh eq 'GLOB'
123 || ref \$fh eq 'GLOB' )
124 {
125 0 croak "Given argument is no valid file handle.";
126 }
127  
128 18 return $fh->print( $self->as_string . $NL );
129 }
130  
131 #################
132 ## sanitycheck - Checks if needed Headers exists and belong to each other
133 #####
134  
135 9 ▶sub sanitycheck {
Subroutine sanitycheck: called CC=24 SCAR=52.4
Pod documented
136 9 my $header = shift;
137 9 my $error = 0;
138  
139 # Revision entry needs also 'Prop-content-length' and 'Content-length'
140 9 ▶ if ( exists $header->{'Revision-number'} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $header->{'Revision-number'}) { } 4 5 9
elsif (not exists $header->{'Node-path'}) { } 0 5 5
elsif (not exists $header->{'Node-action'}) { } 0 5 5
141 4 ▶ if ( !exists $header->{'Prop-content-length'}
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $header->{"Prop-content-length"} and exists $header->{"Content-length"}) 0 4 4
Condition33%1/3
exists $header->{"Prop-content-length"} and exists $header->{"Content-length"}
!ll&&!rl&&r
004
MC/DC0%0/2
exists $header->{"Prop-content-length"} and exists $header->{"Content-length"}
exists $header->{"Prop-content-length"} exists $header->{"Content-length"}
Truth table33%1/3
A and B
A= exists $header->{"Prop-content-length"}B= exists $header->{"Content-length"}
ABresult
0X0
100
111
142 || !exists $header->{'Content-length'} )
143 {
144 0 carp "Missing needed header(s) after 'Revision-number'.\n";
145 0 $error++;
146 }
147 }
148  
149 elsif ( !exists $header->{'Node-path'} ) {
150 0 carp "Missing needed header 'Node-path' or 'Revision-number'.";
151 0 return 10_000;
152 }
153  
154 # Nodes need 'Node-action' at minimum.
155 elsif ( !exists $header->{'Node-action'} ) {
156 0 carp "Missing needed header 'Node-action' after 'Node-path'.";
157 0 $error++;
158 }
159 else # 'Node-action' exists:
160 {
161 5 my $action = $header->{'Node-action'}; # buffer
162 5 ▶ if ( $action eq 'delete' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($action eq 'delete') { } 0 5 5
elsif ($action eq 'add' or $action eq 'replace') { } 5 0 5
elsif ($action eq 'change') { } 0 0 0
163 my $num_headers_expected
164 0 ▶ = ( exists $header->{'Node-kind'} ) ? 3 : 2;
Branch: 1 branch
BranchTrueFalseTotal
exists $header->{'Node-kind'} ? : 0 0 0
165  
166 0 ▶ if ( keys %$header != $num_headers_expected ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$header != $num_headers_expected) 0 0 0
167 0 carp "Two much headers for 'Node-action: delete'.\n";
168 0 local $, = "\n";
169  
170 0 ▶ while ( my ( $key, $value ) = each %$header ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$header) 0 0 0
171 0 print STDERR "$key: $value\n";
172 }
173 0 $error++;
174 }
175 }
176 ▶ elsif ( $action eq 'add' or $action eq 'replace' ) {
Condition33%1/3
$action eq "add" or $action eq "replace"
l!l&&r!l&&!r
500
MC/DC0%0/2
$action eq "add" or $action eq "replace"
$action eq "add" $action eq "replace"
Truth table33%1/3
A or B
A= $action eq "add"B= $action eq "replace"
ABresult
1X1
011
000
177 5 ▶ if ( !exists $header->{'Node-kind'} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not exists $header->{'Node-kind'}) { } 0 5 5
elsif ($header->{'Node-kind'} eq 'file') { } 2 3 5
elsif ($header->{'Node-kind'} eq 'dir') { } 3 0 3
178 0 carp "Missing header 'Node-kind' for 'Node-action: add'.\n";
179 0 $error++;
180 }
181 elsif ( $header->{'Node-kind'} eq 'file' ) {
182 2 ▶ unless ( # This two header both exist
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $header->{"Text-content-length"} and exists $header->{"Text-content-md5"} and not exists $header->{"Node-copyfrom-rev"} ^ exists $header->{"Node-copyfrom-path"} or exists $header->{"Node-copyfrom-rev"} and exists $header->{"Node-copyfrom-path"} and not exists $header->{"Text-content-length"} ^ exists $header->{"Text-content-md5"}) 0 2 2
Condition20%3/15
exists $header->{"Text-content-length"} and exists $header->{"Text-content-md5"} and not exists $header->{"Node-copyfrom-rev"} ^ exists $header->{"Node-copyfrom-path"} or exists $header->{"Node-copyfrom-rev"} and exists $header->{"Node-copyfrom-path"} and not exists $header->{"Text-content-length"} ^ exists $header->{"Text-content-md5"}
l!l&&r!l&&!r
200
exists $header->{"Text-content-length"} and exists $header->{"Text-content-md5"} and not exists $header->{"Node-copyfrom-rev"} ^ exists $header->{"Node-copyfrom-path"}
!ll&&!rl&&r
002
exists $header->{"Text-content-length"} and exists $header->{"Text-content-md5"}
!ll&&!rl&&r
002
exists $header->{"Node-copyfrom-rev"} and exists $header->{"Node-copyfrom-path"} and not exists $header->{"Text-content-length"} ^ exists $header->{"Text-content-md5"}
!ll&&!rl&&r
000
exists $header->{"Node-copyfrom-rev"} and exists $header->{"Node-copyfrom-path"}
!ll&&!rl&&r
000
MC/DC0%0/6
exists $header->{"Text-content-length"} and exists $header->{"Text-content-md5"} and not exists $header->{"Node-copyfrom-rev"} ^ exists $header->{"Node-copyfrom-path"} or exists $header->{"Node-copyfrom-rev"} and exists $header->{"Node-copyfrom-path"} and not exists $header->{"Text-content-length"} ^ exists $header->{"Text-content-md5"}
exists $header->{"Text-content-length"} exists $header->{"Text-content-md5"} not exists $header->{"Node-copyfrom-rev"} ^ exists $header->{"Node-copyfrom-path"} exists $header->{"Node-copyfrom-rev"} exists $header->{"Node-copyfrom-path"} not exists $header->{"Text-content-length"} ^ exists $header->{"Text-content-md5"}
Truth table7%1/13
A and B and not(C) or D and E and not(F)
A= exists $header->{"Text-content-length"}B= exists $header->{"Text-content-md5"}C= not exists $header->{"Node-copyfrom-rev"} ^ exists $header->{"Node-copyfrom-path"}D= exists $header->{"Node-copyfrom-rev"}E= exists $header->{"Node-copyfrom-path"}F= not exists $header->{"Text-content-length"} ^ exists $header->{"Text-content-md5"}
ABCDEFresult
111XXX1
0XX1111
10X1111
1101111
0XX0XX0
0XX10X0
0XX1100
10X0XX0
10X10X0
10X1100
1100XX0
11010X0
1101100
183 ( exists $header->{'Text-content-length'}
184 && exists $header->{'Text-content-md5'}
185 && !( # and this two both exist or both non-exist
186 exists $header->{
187 'Node-copyfrom-rev'} ^ #\ xor+negation
188 exists $header->{
189 'Node-copyfrom-path'} #/ = equivalence
190 )
191 )
192 || ( # This two header both exist
193 exists $header->{'Node-copyfrom-rev'}
194 && exists $header->{'Node-copyfrom-path'}
195 && !( # and this two both exist or both non-exist
196 exists $header->{
197 'Text-content-length'} ^ #\ xor+negation
198 exists $header->{
199 'Text-content-md5'} #/ = equivalence
200 )
201 )
202 )
203 { # then there is something wrong
204 0 carp "Missing/wrong header(s) for 'Node-action: add'/"
205 . "'Node-kind: file'.";
206 0 $error++;
207 }
208 }
209 elsif ( $header->{'Node-kind'} eq 'dir' ) {
210 3 ▶ if ( exists $header->{'Text-content-length'}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $header->{"Text-content-length"} or exists $header->{"Text-content-md5"}) 0 3 3
Condition33%1/3
exists $header->{"Text-content-length"} or exists $header->{"Text-content-md5"}
l!l&&r!l&&!r
003
MC/DC0%0/2
exists $header->{"Text-content-length"} or exists $header->{"Text-content-md5"}
exists $header->{"Text-content-length"} exists $header->{"Text-content-md5"}
Truth table33%1/3
A or B
A= exists $header->{"Text-content-length"}B= exists $header->{"Text-content-md5"}
ABresult
1X1
011
000
211 || exists $header->{'Text-content-md5'} )
212 {
213 0 carp "To much header(s) for 'Node-action: add'/'Node-kind:
214 dir'.";
215 0 $error++;
216 }
217 }
218 else {
219 carp "Invalid value '"
220 0 . $header->{'Node-kind'}
221 . "' for 'Node-kind'.";
222 0 $error++;
223 }
224 }
225 elsif ( $action eq 'change' ) {
226  
227 }
228 else {
229  
230 }
231 } # end of else path of "if ( !exists $header->{'Node-action'} )"
232  
233 #print STDERR Data::Dumper->Dump([$header], ['%header']) if $error;
234 9 return $error;
235 }
236  
237 11 1;
238 __END__
↑ Summary Dumpfile/Node.pm »