| 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: Dumpfile.pm 107 2009-04-23 11:45:00Z martin $ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | ################################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | package SVN::Dumpfile; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use SVN::Dumpfile::Node; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use IO::File; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | Readonly my $NL => chr(10); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | our $VERSION = do { '$Rev: 107 $' =~ /\$Rev: (\d+) \$/; '0.13' . ".$1" }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 23 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 23 | my $arg = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 23 | ▶ | my $class = ref $arg ? ref $arg : $arg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 23 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 23 | return $self->_process_arguments(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 34 | ▶ | sub _process_arguments { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_arguments: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 34 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 34 | my @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 34 | ▶ | if ( @_ == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 15 | ▶ | if ( ref $_[0] eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | @args = %{ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | elsif ( ref $_[0] eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | @args = @{ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | elsif ( my $h = __PACKAGE__->_is_valid_fh( $_[0] ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 5 | $self->{fh} = $h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 5 | @args = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | elsif ( !ref $_[0] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | $self->{file} = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 6 | @args = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | carp "Single argument must be either a hash ref or a filename!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 2 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 19 | @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 32 | ▶ | croak "Final number of arguments not even" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | if @args % 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 31 | %$self = ( %$self, @args ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 31 | ▶ | if ( exists $self->{version} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 3 | $self->{'SVN-fs-dump-format-version'} = $self->{version}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | delete $self->{version}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 31 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | ▶ | sub dump { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | require Data::Dumper; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | print STDERR Data::Dumper->Dump( [ \$self ], ['*self'] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 7 | ▶ | sub uuid : lvalue { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uuid: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 7 | my ( $self, $uuid ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 7 | ▶ | $self->{'UUID'} = $uuid | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | if defined $uuid; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 7 | $self->{'UUID'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 7 | ▶ | sub version : lvalue { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 7 | my ( $self, $version ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 7 | ▶ | $self->{'SVN-fs-dump-format-version'} = $version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | if defined $version; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 7 | $self->{'SVN-fs-dump-format-version'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 28 | ▶ | sub read_node { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_node: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 28 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 28 | my $node = SVN::Dumpfile::Node->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 28 | ▶ | return unless $self->{fh}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 27 | ▶ | $node = undef unless $node->read( $self->{fh} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 27 | return $node; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 6 | *get_node = \&read_node; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 6 | *next_node = \&read_node; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 17 | ▶ | sub write_node { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_node: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 17 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 17 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 17 | ▶ | return if not defined $node; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 16 | return $node->write( $self->{fh} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 7 | ▶ | sub create { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create: called CC=6 SCAR=18.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 7 | ▶ | if ( ref $self ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 6 | ▶ | return unless $self->_process_arguments(@_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | $self = $self->new(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 6 | my $fh = $self->{fh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 6 | my $file = $self->{file}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 6 | ▶ | if ( defined $fh ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 5 | eval { $fh->binmode }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | elsif ( defined $file ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $self->{fh} = $fh = new IO::File; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | $fh->open( $file, '>' ) or croak "Couldn't create file."; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | croak __PACKAGE__ . '::create() needs file name or handle.'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 5 | $fh->print( $self->as_string ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 5 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 7 | ▶ | sub as_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=7 SCAR=20.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 7 | my $string = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 6 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | $self->{'SVN-fs-dump-format-version'} = 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 7 | ▶ | if ( $self->{'SVN-fs-dump-format-version'} < 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | $string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | = "SVN-fs-dump-format-version: " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 7 | . $self->{'SVN-fs-dump-format-version'} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | . $NL x 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 7 | ▶ | if ( $self->{'SVN-fs-dump-format-version'} > 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 6 | ▶ | if ( $self->{'UUID'} eq '' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | $self->{'UUID'} = eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # Use Data::GUID if available | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | require Data::GUID; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | lc ( Data::GUID->new->as_string ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } || eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # Use Data::UUID if available | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | require Data::UUID; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | my $ug = new Data::UUID; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | my $uuid_bin = $ug->create(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | lc( $ug->to_string($uuid_bin) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | ▶ | } || do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
eval {
do {
require Data::GUID;
lc 'Data::GUID'->new->as_string
}
} || eval {
do {
require Data::UUID;
my $ug = 'Data::UUID'->new;
my $uuid_bin = $ug->create;
lc $ug->to_string($uuid_bin)
}
} || do {
my @r;
push @r, rand 65535 foreach (1 .. 9);
sprintf '%04x%04x-%04x-%04x-%04x-%04x%04x%04x', @r
}
eval {
do {
require Data::GUID;
lc "Data::GUID"->new->as_string
}
} or eval {
do {
require Data::UUID;
my $ug = "Data::UUID"->new;
my $uuid_bin = $ug->create;
lc $ug->to_string($uuid_bin)
}
}
MC/DC0%0/3
eval {
do {
require Data::GUID;
lc 'Data::GUID'->new->as_string
}
} || eval {
do {
require Data::UUID;
my $ug = 'Data::UUID'->new;
my $uuid_bin = $ug->create;
lc $ug->to_string($uuid_bin)
}
} || do {
my @r;
push @r, rand 65535 foreach (1 .. 9);
sprintf '%04x%04x-%04x-%04x-%04x-%04x%04x%04x', @r
}
eval {
do {
require Data::GUID;
lc "Data::GUID"->new->as_string
}
}
eval {
do {
require Data::UUID;
my $ug = "Data::UUID"->new;
my $uuid_bin = $ug->create;
lc $ug->to_string($uuid_bin)
}
}
do {
my @r;
push @r, rand 65535 foreach (1 .. 9);
sprintf '%04x%04x-%04x-%04x-%04x-%04x%04x%04x', @r
}
Truth table25%1/4
A or B || C
A= eval {
do {
require Data::GUID;
lc "Data::GUID"->new->as_string
}
}B= eval {
do {
require Data::UUID;
my $ug = "Data::UUID"->new;
my $uuid_bin = $ug->create;
lc $ug->to_string($uuid_bin)
}
}C= do {
my @r;
push @r, rand 65535 foreach (1 .. 9);
sprintf '%04x%04x-%04x-%04x-%04x-%04x%04x%04x', @r
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my @r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # Otherwise just generate a random UUID | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | push( @r, rand( 2**16 - 1 ) ) for ( 1 .. 9 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | sprintf( "%04x%04x-%04x-%04x-%04x-%04x%04x%04x", @r ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 6 | $string .= "UUID: $self->{UUID}" . $NL x 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 7 | return $string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 6 | *to_string = \&as_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 4 | ▶ | sub copy { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
copy: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 4 | my $new = $self->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 4 | foreach my $key (qw(SVN-fs-dump-format-version UUID)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 8 | $new->{$key} = $self->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 4 | return $new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 23 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 23 | shift->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 25 | ▶ | sub close { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
close: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 25 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | $self->{fh}->close | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 25 | ▶ | if defined $self->{fh}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 23 | ▶ | sub version_supported { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version_supported: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 23 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 23 | my $version = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 23 | ▶ | if ( ref $self and not defined $version ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $self and not defined $version
MC/DC100%2/2
ref $self and not defined $version
ref $self
not defined $version
Truth table100%3/3
A and not(B)
A= ref $selfB= not defined $version
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 10 | $version = $self->{'SVN-fs-dump-format-version'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 23 | ▶ | return unless defined $version; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # Versions 1 - 3 are supported | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 22 | ▶ | return ( $version >= 1 && $version <= 3 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$version >= 1 && $version <= 3
MC/DC100%2/2
$version >= 1 && $version <= 3
$version >= 1
$version <= 3
Truth table100%3/3
A && B
A= $version >= 1B= $version <= 3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 40 | ▶ | sub _is_valid_fh { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_valid_fh: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 40 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 40 | my $h = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 40 | ▶ | return if not defined $h; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 39 | ▶ | return $h if eval { $h->isa('IO::Handle') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 6 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | return *$h{IO} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 34 | ▶ | if ref $h eq 'GLOB' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
ref $h eq "GLOB" or ref \$h eq "GLOB" or $h eq "STDIN" or $h eq "STDOUT"
ref $h eq "GLOB" or ref \$h eq "GLOB" or $h eq "STDIN"
ref $h eq "GLOB" or ref \$h eq "GLOB"
MC/DC100%4/4
ref $h eq "GLOB" or ref \$h eq "GLOB" or $h eq "STDIN" or $h eq "STDOUT"
ref $h eq "GLOB"
ref \$h eq "GLOB"
$h eq "STDIN"
$h eq "STDOUT"
Truth table100%5/5
A or B or C or D
A= ref $h eq "GLOB"B= ref \$h eq "GLOB"C= $h eq "STDIN"D= $h eq "STDOUT"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | or ref \$h eq 'GLOB' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | or $h eq 'STDIN' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | or $h eq 'STDOUT'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 15 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 6 | ▶ | sub _is_stdin { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_stdin: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 6 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 6 | my $file = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 6 | ▶ | return ( $file eq '' or $file eq '-' or $file eq 'STDIN' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$file eq '' || $file eq '-' || $file eq 'STDIN'
$file eq "" or $file eq "-"
MC/DC100%3/3
$file eq '' || $file eq '-' || $file eq 'STDIN'
$file eq ""
$file eq "-"
$file eq 'STDIN'
Truth table100%4/4
A or B || C
A= $file eq ""B= $file eq "-"C= $file eq 'STDIN'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 6 | ▶ | sub _is_stdout { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_stdout: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 6 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 6 | my $file = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 6 | ▶ | return ( $file eq '' or $file eq '-' or $file eq 'STDOUT' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$file eq '' || $file eq '-' || $file eq 'STDOUT'
$file eq "" or $file eq "-"
MC/DC100%3/3
$file eq '' || $file eq '-' || $file eq 'STDOUT'
$file eq ""
$file eq "-"
$file eq 'STDOUT'
Truth table100%4/4
A or B || C
A= $file eq ""B= $file eq "-"C= $file eq 'STDOUT'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 5 | ▶ | sub open { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
open: called CC=13 SCAR=28.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 5 | ▶ | if ( ref $self ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 5 | ▶ | return unless $self->_process_arguments(@_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | $self = $self->new(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 5 | my $fh = $self->{fh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 5 | my $file = $self->{file}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 5 | ▶ | if ( defined $fh ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | eval { $fh->binmode }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | elsif ( defined $file ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 5 | $self->{fh} = $fh = new IO::File; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 5 | ▶ | if ( !$fh->open( $file, '<' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | carp "Couldn't open dumpfile."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | croak __PACKAGE__ . '::open() needs file name or handle.'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 5 | my $irs = IO::Handle->input_record_separator($NL); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 5 | my $line = $fh->getline; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 5 | ▶ | if ( $line =~ /^SVN-fs-dump-format-version: (\d+)$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 5 | $self->{'SVN-fs-dump-format-version'} = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 5 | ▶ | if ( !$self->version_supported ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | carp "Warning: Found dump format version ", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | $self->{'SVN-fs-dump-format-version'}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | " is not supported (yet).\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | "Unknown entries will be ignored. Use at your own risk.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | carp "Error: Dumpfile looks invalid. Couldn't find valid ", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | "'SVN-fs-dump-format-version' header.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 5 | ▶ | if ( $self->{'SVN-fs-dump-format-version'} > 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 4 | my $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 4 | ▶ | while ( ( $char = $fh->getc ) eq "\012" ) { } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 4 | ▶ | if ( $char eq 'U' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 3 | $line = $char . $fh->getline; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 3 | ▶ | if ( $line =~ /^UUID: (.*)$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 3 | $self->{'UUID'} = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # read blank line after UUID: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 3 | $char = $fh->getc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 3 | ▶ | $fh->ungetc( ord $char ) if ( $char ne "\012" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | carp "Error: Dumpfile looks invalid. Couldn't find valid ", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | "'UUID' header.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 1 | carp "Error: Dumpfile looks invalid. Couldn't find valid ", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | "'UUID' header.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 1 | $fh->ungetc( ord $char ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 5 | IO::Handle->input_record_separator($irs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 5 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||