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