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   310748 use strict;
  4         43  
  4         110  
4 4     4   23 use warnings;
  4         4  
  4         91  
5 4     4   18 use Carp;
  4         10  
  4         208  
6              
7 4     4   1798 use SVN::Dump::Reader;
  4         777  
  4         2087  
8              
9             our $VERSION = '0.06';
10              
11             sub new {
12 33     33 1 34986 my ( $class, $args ) = @_;
13 33         77 my $self = bless {}, $class;
14              
15             # FIXME - croak() if incompatible options
16              
17             # we have a reader
18 33 100 100     189 if ( exists $args->{fh} || exists $args->{file} ) {
19 30         56 my ( $fh, $file ) = delete @{$args}{qw( fh file )};
  30         102  
20 30 100       73 if ( !$fh ) {
21 25 100       1072 open $fh, $file or croak "Can't open $file: $!";
22             }
23 29         195 $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         5 $self->{uuid} = SVN::Dump::Record->new();
34 2         5 $self->{uuid}->set_header( 'UUID' => $args->{uuid} );
35             }
36             }
37              
38 32         229 return $self;
39             }
40              
41             sub next_record {
42 542     542 1 4753 my ($self) = @_;
43 542         662 my $record;
44              
45             RECORD: {
46 542         679 $record = $self->{reader}->read_record();
  542         1143  
47 542 100       1044 return unless $record;
48              
49             # keep the first records in the dump itself
50 514         1042 my $type = $record->type();
51 514 100       1623 if ( $type =~ /\A(?:format|uuid)\z/ ) {
52 58         150 $self->{$type} = $record;
53             }
54             }
55              
56 514         951 return $record;
57             }
58              
59             sub version {
60 4     4 1 17 my ($self) = @_;
61             return $self->{format}
62 4 100       20 ? $self->{format}->get_header('SVN-fs-dump-format-version')
63             : '';
64             }
65             *format = \&version;
66              
67             sub uuid {
68 4     4 1 9 my ($self) = @_;
69 4 100       14 return $self->{uuid} ? $self->{uuid}->get_header('UUID') : '';
70             }
71              
72             sub as_string {
73 1     1 1 3 return join '', map { $_[0]->{$_}->as_string() } qw( format uuid );
  2         8  
74             }
75              
76             1;
77              
78             __END__