blib/lib/SVN/Dump/Record.pm

filter: Statementstmt 100% 83 / 83 Branchbran 100% 26 / 26 Conditioncond 66.6% 12 / 18 MC/DCmcdc 25.0% 3 / 12 Subroutinesub 100% 25 / 25 Podpod 100% 17 / 17 totaltotal 91.7% 166 / 181 SCAR 30.0
CC
20
Cov
95%
as_string
7.0
delete_property
3.1
update_headers
3.0
CRAP 20.0
« blib/lib/SVN/Dump/Reader.pm ↑ Summary blib/lib/SVN/Dump/Headers.pm »
1 package SVN::Dump::Record;
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 12 ▶use SVN::Dump::Headers;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use SVN::Dump::Property;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use SVN::Dump::Text;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 12 my $NL = "\012";
11  
12 sub new {
13 731 ▶ my ($class, @args) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
14 731 return bless {}, $class
15 }
16  
17 12 for my $attr (qw( headers_block property_block text_block included_record )) {
18 12 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1243 ▶ *{"set_$attr"} = sub { $_[0]->{$attr} = $_[1]; };
Subroutine __ANON__: called CC=1 SCAR=0.0
20 5308 ▶ *{"get_$attr"} = sub { $_[0]->{$attr} };
Subroutine __ANON__: called CC=1 SCAR=0.0
21 }
22  
23 sub type {
24 1346 ▶ my ($self) = @_;
Subroutine type: called CC=2 SCAR=6.9
Pod documented
25 1346 ▶ return $self->{headers_block} ? $self->{headers_block}->type() : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'headers_block'} ? : 1345 1 1346
26 }
27  
28 847 ▶sub has_text { return defined $_[0]->get_text_block(); }
Subroutine has_text: called CC=1 SCAR=0.0
Pod documented
29 847 ▶sub has_prop { return defined $_[0]->get_property_block(); }
Subroutine has_prop: called CC=1 SCAR=0.0
Pod documented
30 sub has_prop_only {
31 2 ▶ return defined $_[0]->get_property_block()
Subroutine has_prop_only: called CC=2 SCAR=7.2
Pod documented
Condition66%2/3
defined $_[0]->get_property_block && !defined($_[0]->get_text_block)
!ll&&!rl&&r
011
MC/DC50%1/2
defined $_[0]->get_property_block && !defined($_[0]->get_text_block)
defined $_[0]->get_property_block !defined($_[0]->get_text_block)
Truth table66%2/3
A && not(B)
A= defined $_[0]->get_property_blockB= !defined($_[0]->get_text_block)
ABresult
0X0
100
111
32 && !defined $_[0]->get_text_block();
33 }
34 sub has_prop_or_text {
35 446 ▶ return defined $_[0]->get_property_block()
Subroutine has_prop_or_text: called CC=2 SCAR=6.9
Pod documented
Condition100%3/3
defined $_[0]->get_property_block || defined $_[0]->get_text_block
l!l&&r!l&&!r
26611169
MC/DC100%2/2
defined $_[0]->get_property_block || defined $_[0]->get_text_block
defined $_[0]->get_property_block defined $_[0]->get_text_block
Truth table100%3/3
A || B
A= defined $_[0]->get_property_blockB= defined $_[0]->get_text_block
ABresult
1X1
011
000
36 || defined $_[0]->get_text_block();
37 }
38  
39 # length methods
40 sub property_length {
41 36 ▶ my ($self) = @_;
Subroutine property_length: called CC=2 SCAR=6.9
Pod documented
42 36 my $prop = $self->get_property_block();
43 36 ▶ return defined $prop ? length( $prop->as_string() ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $prop ? : 32 4 36
44 }
45  
46 sub text_length {
47 38 ▶ my ($self) = @_;
Subroutine text_length: called CC=2 SCAR=6.9
Pod documented
48 38 my $text = $self->get_text();
49 38 ▶ return defined $text ? length($text) : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $text ? : 34 4 38
50 }
51  
52 sub as_string {
53 844 ▶ my ($self) = @_;
Subroutine as_string: called CC=7 SCAR=19.5
Pod documented
54 844 my $headers_block = $self->get_headers_block();
55  
56 # the headers block
57 844 my $string = $headers_block->as_string();
58  
59 # the properties
60 844 ▶ $string .= $self->get_property_block()->as_string()
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_prop 570 274 844
61 if $self->has_prop();
62  
63 # the text
64 844 ▶ $string .= $self->get_text_block()->as_string()
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_text 118 726 844
65 if $self->has_text();
66  
67 # is there an included record?
68 844 ▶ if( my $included = $self->get_included_record() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $included = $self->get_included_record) 1 843 844
69 1 $string .= $included->as_string() . $NL;
70 }
71  
72 # add a record separator if needed
73 844 my $type = $self->type();
74 844 ▶ return $string if $type =~ /\A(?:format|uuid)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $type =~ /\A(?:format|uuid)\z/ 94 750 844
75  
76 750 ▶ $string .= $type eq 'revision' ? $NL
Branch: 2 branches
BranchTrueFalseTotal
$type eq 'revision' ? : 306 444 750
$self->has_prop_or_text ? : 275 169 444
77 : $self->has_prop_or_text() ? $NL x 2
78 : $NL ;
79  
80 750 return $string;
81 }
82  
83 sub update_headers {
84 35 ▶ my ($self) = @_;
Subroutine update_headers: called CC=3 SCAR=11.0
Pod documented
85 35 my $proplen = $self->property_length();
86 35 my $textlen = $self->text_length();
87  
88 35 ▶ $self->set_header( 'Text-content-length' => $textlen )
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->get_text_block 32 3 35
89 if defined $self->get_text_block();
90 35 ▶ $self->set_header( 'Prop-content-length', $proplen )
Branch: 1 branch
BranchTrueFalseTotal
if $proplen 32 3 35
91 if $proplen;
92 35 $self->set_header( 'Content-length' => $proplen + $textlen );
93 }
94  
95 # access methods to the inner blocks
96 sub set_header {
97 109 ▶ my ($self, $h, $v) = @_;
Subroutine set_header: called CC=2 SCAR=7.0
Pod documented
98 109 ▶ my $headers = $self->get_headers_block()
Condition66%2/3
$self->get_headers_block || $self->set_headers_block('SVN::Dump::Headers'->new)
l!l&&r!l&&!r
10360
MC/DC0%0/2
$self->get_headers_block || $self->set_headers_block('SVN::Dump::Headers'->new)
$self->get_headers_block $self->set_headers_block('SVN::Dump::Headers'->new)
Truth table66%2/3
A || B
A= $self->get_headers_blockB= $self->set_headers_block('SVN::Dump::Headers'->new)
ABresult
1X1
011
000
99 || $self->set_headers_block( SVN::Dump::Headers->new() );
100 109 $headers->set( $h, $v );
101 }
102  
103 sub get_header {
104 176 ▶ my ($self, $h) = @_;
Subroutine get_header: called CC=1 SCAR=0.0
Pod documented
105 176 return $self->get_headers_block()->get($h);
106 }
107  
108 sub set_property {
109 6 ▶ my ( $self, $k, $v ) = @_;
Subroutine set_property: called CC=2 SCAR=7.0
Pod documented
110 6 ▶ my $prop = $self->get_property_block()
Condition66%2/3
$self->get_property_block || $self->set_property_block('SVN::Dump::Property'->new)
l!l&&r!l&&!r
510
MC/DC0%0/2
$self->get_property_block || $self->set_property_block('SVN::Dump::Property'->new)
$self->get_property_block $self->set_property_block('SVN::Dump::Property'->new)
Truth table66%2/3
A || B
A= $self->get_property_blockB= $self->set_property_block('SVN::Dump::Property'->new)
ABresult
1X1
011
000
111 || $self->set_property_block( SVN::Dump::Property->new() );
112 6 $prop->set( $k, $v );
113 6 $self->update_headers();
114 6 return $v;
115 }
116  
117 sub get_property {
118 3 ▶ my ($self, $k) = @_;
Subroutine get_property: called CC=1 SCAR=0.0
Pod documented
119 3 return $self->get_property_block()->get($k);
120 }
121  
122 sub delete_property {
123 3 ▶ my ( $self, @keys ) = @_;
Subroutine delete_property: called CC=3 SCAR=11.2
Pod documented
124 3 ▶ my $prop = $self->get_property_block()
Condition33%1/3
$self->get_property_block || $self->set_property_block('SVN::Dump::Property'->new)
l!l&&r!l&&!r
300
MC/DC0%0/2
$self->get_property_block || $self->set_property_block('SVN::Dump::Property'->new)
$self->get_property_block $self->set_property_block('SVN::Dump::Property'->new)
Truth table33%1/3
A || B
A= $self->get_property_blockB= $self->set_property_block('SVN::Dump::Property'->new)
ABresult
1X1
011
000
125 || $self->set_property_block( SVN::Dump::Property->new() );
126 3 my @result = $prop->delete(@keys);
127 3 $self->update_headers();
128 3 ▶ return wantarray ? @result : pop @result; # behave like delete()
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 2 3
129 }
130  
131 sub set_text {
132 26 ▶ my ($self, $t) = @_;
Subroutine set_text: called CC=2 SCAR=7.0
Pod documented
133 26 ▶ my $text_block = $self->get_text_block()
Condition66%2/3
$self->get_text_block || $self->set_text_block('SVN::Dump::Text'->new)
l!l&&r!l&&!r
2420
MC/DC0%0/2
$self->get_text_block || $self->set_text_block('SVN::Dump::Text'->new)
$self->get_text_block $self->set_text_block('SVN::Dump::Text'->new)
Truth table66%2/3
A || B
A= $self->get_text_blockB= $self->set_text_block('SVN::Dump::Text'->new)
ABresult
1X1
011
000
134 || $self->set_text_block( SVN::Dump::Text->new() );
135  
136 26 $text_block->set( $t );
137 26 $self->update_headers();
138 26 return $t;
139 }
140  
141 sub get_text {
142 206 ▶ my ($self) = @_;
Subroutine get_text: called CC=2 SCAR=6.9
Pod documented
143 206 my $text_block = $self->get_text_block();
144 206 ▶ return defined $text_block ? $text_block->get() : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $text_block ? : 58 148 206
145 }
146  
147 12 1;
148  
149 __END__
« blib/lib/SVN/Dump/Reader.pm ↑ Summary blib/lib/SVN/Dump/Headers.pm »