line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
################################################################################ |
2
|
|
|
|
|
|
|
# Copyright (c) 2008 Martin Scharrer |
3
|
|
|
|
|
|
|
# This is open source software under the GPL v3 or later. |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# $Id: Content.pm 103 2008-10-14 21:11:21Z martin $ |
6
|
|
|
|
|
|
|
################################################################################ |
7
|
|
|
|
|
|
|
package SVN::Dumpfile::Node::Content; |
8
|
12
|
|
|
12
|
|
57696
|
use IO::File; |
|
12
|
|
|
|
|
20
|
|
|
12
|
|
|
|
|
2051
|
|
9
|
12
|
|
|
12
|
|
69
|
use Carp; |
|
12
|
|
|
|
|
23
|
|
|
12
|
|
|
|
|
794
|
|
10
|
12
|
|
|
12
|
|
62
|
use strict; |
|
12
|
|
|
|
|
26
|
|
|
12
|
|
|
|
|
365
|
|
11
|
12
|
|
|
12
|
|
59
|
use warnings; |
|
12
|
|
|
|
|
20
|
|
|
12
|
|
|
|
|
373
|
|
12
|
12
|
|
|
12
|
|
928
|
use Readonly; |
|
12
|
|
|
|
|
3238
|
|
|
12
|
|
|
|
|
1679
|
|
13
|
|
|
|
|
|
|
Readonly my $NL => chr(10); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = do { '$Rev: 103 $' =~ /\$Rev: (\d+) \$/; '0.13' . ".$1" }; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use overload |
18
|
12
|
|
|
|
|
108
|
'""' => \&as_string, |
19
|
12
|
|
|
12
|
|
15103
|
fallback => 1; |
|
12
|
|
|
|
|
10775
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
46
|
|
|
46
|
1
|
2712
|
my $class = shift; |
23
|
46
|
|
|
|
|
81
|
my $scalar = shift; |
24
|
46
|
|
33
|
|
|
274
|
my $self = bless \$scalar, ref $class || $class; |
25
|
46
|
|
|
|
|
302
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub exists { |
29
|
6
|
|
|
6
|
1
|
9
|
my $self = shift; |
30
|
6
|
|
66
|
|
|
48
|
return ( defined $$self and $$self ne '' ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub delete { |
34
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
35
|
2
|
|
|
|
|
4
|
$$self = undef; |
36
|
2
|
|
|
|
|
7
|
return; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub value : lvalue { |
40
|
18
|
|
|
18
|
1
|
1343
|
my $self = shift; |
41
|
18
|
|
|
|
|
26
|
my $newvalue = shift; |
42
|
18
|
100
|
|
|
|
56
|
$$self = $newvalue |
43
|
|
|
|
|
|
|
if defined $newvalue; |
44
|
18
|
|
|
|
|
110
|
$$self; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub as_string { |
48
|
43
|
|
|
43
|
1
|
1923
|
my $self = shift; |
49
|
43
|
100
|
|
|
|
435
|
return ( ( defined $$self ) ? $$self : '' ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
*to_string = \&as_string; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub read { |
55
|
8
|
|
|
8
|
1
|
18
|
my ( $self, $fh, $length ) = @_; |
56
|
8
|
|
|
|
|
97
|
return $fh->read( $$self, $length ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub write { |
60
|
5
|
|
|
5
|
1
|
9
|
my $self = shift; |
61
|
5
|
|
|
|
|
7
|
my $fh = shift; |
62
|
|
|
|
|
|
|
|
63
|
5
|
0
|
33
|
|
|
6
|
unless ( eval { $fh->isa('IO::Handle') } |
|
5
|
|
33
|
|
|
25
|
|
64
|
|
|
|
|
|
|
|| ref $fh eq 'GLOB' |
65
|
|
|
|
|
|
|
|| ref \$fh eq 'GLOB' ) |
66
|
|
|
|
|
|
|
{ |
67
|
0
|
|
|
|
|
0
|
croak "Given argument is no valid file handle."; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
5
|
50
|
|
|
|
21
|
return ($$self) ? $fh->print($$self) : '0 but true'; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub save { |
74
|
1
|
|
|
1
|
1
|
311
|
my ( $self, $fr ) = @_; |
75
|
1
|
|
|
|
|
3
|
my $fh; |
76
|
1
|
50
|
33
|
|
|
10
|
return unless defined $fr and defined $$self; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# $fr can be filename or handle |
79
|
1
|
50
|
|
|
|
3
|
if ( !ref $fr ) { |
|
|
0
|
|
|
|
|
|
80
|
1
|
|
|
|
|
1
|
$fh = eval { new IO::File $fr, '>' }; |
|
1
|
|
|
|
|
6
|
|
81
|
1
|
50
|
|
|
|
140
|
if ( !$fh ) { |
82
|
0
|
|
|
|
|
0
|
carp("Can't print to given filename!"); |
83
|
0
|
|
|
|
|
0
|
return; |
84
|
|
|
|
|
|
|
} |
85
|
1
|
|
|
|
|
5
|
$fh->binmode; |
86
|
|
|
|
|
|
|
} |
87
|
0
|
|
|
|
|
0
|
elsif ( eval { $fr->can('print') } ) { |
88
|
0
|
|
|
|
|
0
|
$fh = $fr; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
else { |
91
|
0
|
|
|
|
|
0
|
carp("Can't print to given handle!"); |
92
|
0
|
|
|
|
|
0
|
return; |
93
|
|
|
|
|
|
|
} |
94
|
1
|
|
|
|
|
15
|
return $fh->print($$self); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub load { |
98
|
12
|
|
|
12
|
|
13335
|
use bytes; |
|
12
|
|
|
|
|
33
|
|
|
12
|
|
|
|
|
187
|
|
99
|
2
|
|
|
2
|
1
|
16
|
my ( $self, $fr ) = @_; |
100
|
2
|
|
|
|
|
4
|
my $fh; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# $fr can be filename or handle |
103
|
2
|
50
|
|
|
|
9
|
if ( !ref $fr ) { |
|
|
0
|
|
|
|
|
|
104
|
2
|
|
|
|
|
6
|
$fh = eval { new IO::File $fr, '<' }; |
|
2
|
|
|
|
|
17
|
|
105
|
2
|
50
|
|
|
|
219
|
return unless $fh; |
106
|
2
|
|
|
|
|
9
|
$fh->binmode; |
107
|
|
|
|
|
|
|
} |
108
|
0
|
|
|
|
|
0
|
elsif ( eval { $fr->can('getlines') } ) { |
109
|
0
|
|
|
|
|
0
|
$fh = $fr; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
else { |
112
|
0
|
|
|
|
|
0
|
carp "Can't print to given handle!"; |
113
|
0
|
|
|
|
|
0
|
return; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
2
|
|
|
|
|
80
|
$$self = join '', $fh->getlines; |
117
|
2
|
|
|
|
|
126
|
return bytes::length($$self); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub lines { |
121
|
3
|
|
|
3
|
1
|
4
|
my $self = shift; |
122
|
3
|
|
|
|
|
5
|
my $lines = 0; |
123
|
3
|
|
|
|
|
7
|
$lines = ( $self =~ tr/\012// ); |
124
|
3
|
100
|
|
|
|
15
|
$lines++ if $self !~ /$NL\Z/m; |
125
|
3
|
|
|
|
|
12
|
return $lines; # Count lines |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub length { |
129
|
12
|
|
|
12
|
|
2948
|
use bytes; |
|
12
|
|
|
|
|
25
|
|
|
12
|
|
|
|
|
65
|
|
130
|
17
|
|
|
17
|
1
|
25
|
my $self = shift; |
131
|
17
|
100
|
|
|
|
107
|
return 0 unless defined $$self; |
132
|
4
|
|
|
|
|
14
|
return bytes::length $$self; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
1; |
136
|
|
|
|
|
|
|
__END__ |