File Coverage

blib/lib/SVN/Dump.pm
Criterion Covered Total %
statement 42 42 100.0
branch 18 18 100.0
condition 3 3 100.0
subroutine 9 9 100.0
pod 5 5 100.0
total 77 77 100.0


line stmt bran cond sub pod time code
1             package SVN::Dump;
2              
3 4     4   273155 use strict;
  4         33  
  4         97  
4 4     4   17 use warnings;
  4         6  
  4         74  
5 4     4   15 use Carp;
  4         6  
  4         189  
6              
7 4     4   1616 use SVN::Dump::Reader;
  4         712  
  4         1822  
8              
9             our $VERSION = '0.06';
10              
11             sub new {
12 33     33 1 33641 my ( $class, $args ) = @_;
13 33         71 my $self = bless {}, $class;
14              
15             # FIXME - croak() if incompatible options
16              
17             # we have a reader
18 33 100 100     174 if ( exists $args->{fh} || exists $args->{file} ) {
19 30         41 my ( $fh, $file ) = delete @{$args}{qw( fh file )};
  30         89  
20 30 100       59 if ( !$fh ) {
21 25 100       1015 open $fh, $file or croak "Can't open $file: $!";
22             }
23 29         174 $self->{reader} = SVN::Dump::Reader->new( $fh, $args );
24             }
25             # we don't have a reader
26             else {
27 3 100       8 if( exists $args->{version} ) {
28 2         6 $self->{format} = SVN::Dump::Record->new();
29             $self->{format}->set_header(
30 2         6 'SVN-fs-dump-format-version' => $args->{version} );
31             }
32 3 100       8 if( exists $args->{uuid} ) {
33 2         6 $self->{uuid} = SVN::Dump::Record->new();
34 2         7 $self->{uuid}->set_header( 'UUID' => $args->{uuid} );
35             }
36             }
37              
38 32         203 return $self;
39             }
40              
41             sub next_record {
42 542     542 1 4075 my ($self) = @_;
43 542         617 my $record;
44              
45             RECORD: {
46 542         667 $record = $self->{reader}->read_record();
  542         1014  
47 542 100       880 return unless $record;
48              
49             # keep the first records in the dump itself
50 514         890 my $type = $record->type();
51 514 100       1356 if ( $type =~ /\A(?:format|uuid)\z/ ) {
52 58         106 $self->{$type} = $record;
53             }
54             }
55              
56 514         832 return $record;
57             }
58              
59             sub version {
60 4     4 1 22 my ($self) = @_;
61             return $self->{format}
62 4 100       16 ? $self->{format}->get_header('SVN-fs-dump-format-version')
63             : '';
64             }
65             *format = \&version;
66              
67             sub uuid {
68 4     4 1 11 my ($self) = @_;
69 4 100       17 return $self->{uuid} ? $self->{uuid}->get_header('UUID') : '';
70             }
71              
72             sub as_string {
73 1     1 1 4 return join '', map { $_[0]->{$_}->as_string() } qw( format uuid );
  2         7  
74             }
75              
76             1;
77              
78             __END__