File Coverage

blib/lib/SVN/Dump/Headers.pm
Criterion Covered Total %
statement 37 37 100.0
branch 14 14 100.0
condition 5 6 83.3
subroutine 10 10 100.0
pod 6 6 100.0
total 72 73 98.6


line stmt bran cond sub pod time code
1             package SVN::Dump::Headers;
2             $SVN::Dump::Headers::VERSION = '0.08';
3 12     12   69062 use strict;
  12         26  
  12         298  
4 12     12   52 use warnings;
  12         18  
  12         227  
5 12     12   59 use Carp;
  12         20  
  12         903  
6 12     12   61 use Scalar::Util qw( reftype );
  12         20  
  12         5788  
7              
8             my $NL = "\012";
9              
10             sub new {
11 711     711 1 4817 my ( $class, $headers ) = @_;
12 711 100 66     1597 croak 'First parameter must be a HASH reference'
      100        
13             if defined $headers
14             && !( ref $headers && reftype $headers eq 'HASH' );
15 708         1041 my $self = bless {}, $class;
16 708 100       843 $self->set( $_ => $headers->{$_} ) for keys %{ $headers || {} };
  708         2416  
17 708         1552 return $self;
18             }
19              
20             my %headers = (
21             revision => [
22             qw(
23             Revision-number
24             Prop-content-length
25             Content-length
26             )
27              
28             ],
29             node => [
30             qw(
31             Node-path
32             Node-kind
33             Node-action
34             Node-copyfrom-rev
35             Node-copyfrom-path
36             Prop-delta
37             Prop-content-length
38             Text-copy-source-md5
39             Text-copy-source-sha1
40             Text-delta
41             Text-content-length
42             Text-content-md5
43             Text-content-sha1
44             Content-length
45             )
46             ],
47             uuid => ['UUID'],
48             format => ['SVN-fs-dump-format-version'],
49             );
50              
51             # FIXME Prop-delta and Text-delta in version 3
52              
53             sub as_string {
54 863     863 1 1087 my ($self) = @_;
55 863         987 my $string = '';
56              
57 863         928 for my $k ( @{ $headers{ $self->type() } } ) {
  863         1154  
58             $string .= "$k: $self->{$k}$NL"
59 7376 100       13560 if exists $self->{$k};
60             }
61              
62 863         1852 return $string . $NL;
63             }
64              
65             sub type {
66 2248     2248 1 3045 my ($self) = @_;
67              
68             my $type =
69             exists $self->{'Node-path'} ? 'node'
70             : exists $self->{'Revision-number'} ? 'revision'
71             : exists $self->{'UUID'} ? 'uuid'
72 2248 100       3849 : exists $self->{'SVN-fs-dump-format-version'} ? 'format'
    100          
    100          
    100          
73             : croak 'Unable to determine the record type';
74              
75 2245         4063 return $type;
76             }
77              
78             sub set {
79 120     120 1 2371 my ($self, $h, $v) = @_;
80              
81             # FIXME shall we check that the header value is valid?
82 120         161 $h =~ tr/_/-/; # allow _ for - simplification
83 120         252 return $self->{$h} = $v;
84             }
85              
86             sub get {
87 186     186 1 2392 my ($self, $h) = @_;
88 186         259 $h =~ tr/_/-/; # allow _ for - simplification
89 186         369 return $self->{$h};
90             }
91              
92             sub keys {
93 6     6 1 1087 my ($self) = @_;
94 6         9 return grep { exists $self->{$_} } @{ $headers{$self->type()} };
  12         41  
  6         14  
95             }
96              
97             1;
98              
99             __END__