line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::DSV; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
4
|
7
|
|
|
7
|
|
58775
|
use strict; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
196
|
|
5
|
7
|
|
|
7
|
|
40
|
use warnings; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
3681
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# Version. |
8
|
|
|
|
|
|
|
our $VERSION = 0.10; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# Constructor. |
11
|
|
|
|
|
|
|
sub new { |
12
|
5
|
|
|
5
|
1
|
55
|
my ($class, @params) = @_; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Create object. |
15
|
5
|
|
|
|
|
13
|
my $self = bless {}, $class; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Object. |
18
|
5
|
|
|
|
|
17
|
return $self; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Parse all data. |
22
|
|
|
|
|
|
|
sub parse { |
23
|
5
|
|
|
5
|
1
|
3433
|
my ($self, $data) = @_; |
24
|
5
|
|
|
|
|
8
|
my @data_lines; |
25
|
5
|
|
|
|
|
17
|
foreach my $line (split m/\n/ms, $data) { |
26
|
14
|
100
|
100
|
|
|
85
|
if ($line =~ m/^\s*$/ms || $line =~ m/^\s*#/) { |
27
|
4
|
|
|
|
|
7
|
next; |
28
|
|
|
|
|
|
|
} |
29
|
10
|
|
|
|
|
19
|
push @data_lines, [$self->parse_line($line)]; |
30
|
|
|
|
|
|
|
} |
31
|
5
|
|
|
|
|
23
|
return @data_lines; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Parse one line. |
35
|
|
|
|
|
|
|
sub parse_line { |
36
|
16
|
|
|
16
|
1
|
3539
|
my ($self, $line) = @_; |
37
|
16
|
|
|
|
|
75
|
my @data_line = split m/(?
|
38
|
16
|
|
|
|
|
25
|
foreach my $data (@data_line) { |
39
|
43
|
|
|
|
|
43
|
$data =~ s/\\:/:/gms; |
40
|
43
|
|
|
|
|
67
|
$data =~ s/\\n/\n/gms; |
41
|
|
|
|
|
|
|
} |
42
|
16
|
|
|
|
|
64
|
return @data_line; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Serialize all data. |
46
|
|
|
|
|
|
|
sub serialize { |
47
|
1
|
|
|
1
|
1
|
8
|
my ($self, @data_lines) = @_; |
48
|
1
|
|
|
|
|
2
|
my $ret; |
49
|
1
|
|
|
|
|
3
|
foreach my $data_line_ar (@data_lines) { |
50
|
2
|
|
|
|
|
3
|
$ret .= $self->serialize_line(@{$data_line_ar})."\n"; |
|
2
|
|
|
|
|
7
|
|
51
|
|
|
|
|
|
|
} |
52
|
1
|
|
|
|
|
4
|
return $ret; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Serialize one line. |
56
|
|
|
|
|
|
|
sub serialize_line { |
57
|
8
|
|
|
8
|
1
|
2525
|
my ($self, @data_line) = @_; |
58
|
8
|
|
|
|
|
13
|
my @escape_data = @data_line; |
59
|
8
|
|
|
|
|
13
|
foreach my $data (@escape_data) { |
60
|
19
|
|
|
|
|
33
|
$data =~ s/:/\\:/gms; |
61
|
19
|
|
|
|
|
34
|
$data =~ s/\n/\\n/gms; |
62
|
|
|
|
|
|
|
} |
63
|
8
|
|
|
|
|
33
|
return join ':', @escape_data; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |