line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Convert::Transcribe; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
66013
|
use 5.005; |
|
8
|
|
|
|
|
35
|
|
|
8
|
|
|
|
|
338
|
|
4
|
8
|
|
|
8
|
|
49
|
use strict; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
274
|
|
5
|
8
|
|
|
8
|
|
41
|
use Carp; |
|
8
|
|
|
|
|
30
|
|
|
8
|
|
|
|
|
765
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
8
|
|
|
8
|
|
47
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
8
|
|
|
|
|
28
|
|
|
8
|
|
|
|
|
8424
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
%EXPORT_TAGS = (); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
@EXPORT_OK = (); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
@EXPORT = (); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$VERSION = '0.02'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
8
|
|
|
8
|
0
|
3111
|
my $class = shift; |
22
|
8
|
|
|
|
|
27
|
my $self = {}; |
23
|
8
|
|
|
|
|
24
|
bless($self, $class); |
24
|
8
|
100
|
|
|
|
37
|
if (defined($_[0])) { |
25
|
6
|
100
|
|
|
|
41
|
if ($_[0] =~ /[\n\r]/) { |
26
|
3
|
|
|
|
|
15
|
fromstring($self, $_[0]); |
27
|
|
|
|
|
|
|
} else { |
28
|
3
|
|
|
|
|
15
|
fromfile($self, $_[0]); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
8
|
|
|
|
|
27
|
return $self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub fromfile { |
35
|
4
|
|
|
4
|
0
|
206
|
my $self = shift; |
36
|
4
|
|
|
|
|
9
|
my ($filename) = @_; |
37
|
4
|
50
|
|
|
|
219
|
open TLT, "<$filename" or croak "Cannot open $filename"; |
38
|
4
|
|
|
|
|
129
|
while () { |
39
|
16
|
|
|
|
|
28
|
chomp; |
40
|
16
|
|
|
|
|
20
|
push @{$self->{DATA}}, $_; |
|
16
|
|
|
|
|
94
|
|
41
|
|
|
|
|
|
|
} |
42
|
4
|
|
|
|
|
43
|
close TLT; |
43
|
4
|
|
|
|
|
30
|
_genfunc($self); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub fromstring { |
47
|
4
|
|
|
4
|
0
|
187
|
my $self = shift; |
48
|
4
|
|
|
|
|
10
|
my ($string) = @_; |
49
|
4
|
|
|
|
|
16
|
chomp($string); |
50
|
4
|
|
|
|
|
33
|
@{$self->{DATA}} = split(/[\r\n]+/, $string); |
|
4
|
|
|
|
|
44
|
|
51
|
4
|
|
|
|
|
20
|
_genfunc($self); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _genfunc { |
56
|
8
|
|
|
8
|
|
15
|
my $self = shift; |
57
|
8
|
|
|
|
|
16
|
my (@r, $t, $neg, $ch, $sub, @cond, $i); |
58
|
|
|
|
|
|
|
|
59
|
8
|
|
|
|
|
18
|
$sub = "my \$tr = '';\nwhile (length) {\n"; |
60
|
8
|
|
|
|
|
16
|
@cond = (); |
61
|
|
|
|
|
|
|
|
62
|
8
|
|
|
|
|
16
|
foreach (@{$self->{DATA}}) { |
|
8
|
|
|
|
|
25
|
|
63
|
39
|
|
|
|
|
63
|
($t, $neg) = ('', 0); |
64
|
39
|
|
|
|
|
86
|
s/\#.*//; |
65
|
39
|
|
|
|
|
84
|
s/([\'\"\/])/\\$1/g; |
66
|
39
|
|
|
|
|
114
|
while (/[\<\>]/) { |
67
|
10
|
50
|
|
|
|
122
|
s/([\<\>][^\<\>]+)// and push @cond, [split(' ', $1)]; |
68
|
|
|
|
|
|
|
} |
69
|
39
|
|
|
|
|
120
|
@r = split; |
70
|
39
|
100
|
|
|
|
113
|
if (@r == 2) { |
71
|
|
|
|
|
|
|
|
72
|
34
|
|
|
|
|
52
|
foreach $i (@cond) { |
73
|
|
|
|
|
|
|
|
74
|
10
|
|
|
|
|
21
|
$t = shift @$i; |
75
|
|
|
|
|
|
|
|
76
|
10
|
100
|
|
|
|
26
|
if ($i->[0] eq '!') { |
77
|
3
|
|
|
|
|
5
|
$ch = '!'; |
78
|
3
|
|
|
|
|
4
|
shift @$i; |
79
|
|
|
|
|
|
|
} else { |
80
|
7
|
|
|
|
|
14
|
$ch = '='; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
10
|
|
|
|
|
13
|
my $reg = '('; my $del = ''; |
|
10
|
|
|
|
|
14
|
|
84
|
10
|
|
|
|
|
21
|
foreach (@$i) { |
85
|
10
|
|
|
|
|
11
|
$reg .= $del; |
86
|
|
|
|
|
|
|
|
87
|
10
|
100
|
|
|
|
23
|
if ($_ eq '$') { |
88
|
6
|
100
|
|
|
|
19
|
$reg .= ($t eq '>'? '\s|$': '^|\s'); |
89
|
|
|
|
|
|
|
} else { |
90
|
4
|
|
|
|
|
6
|
$reg .= $_; |
91
|
|
|
|
|
|
|
} |
92
|
10
|
|
|
|
|
23
|
$del = '|'; |
93
|
|
|
|
|
|
|
} |
94
|
10
|
|
|
|
|
15
|
$reg .= ')'; |
95
|
|
|
|
|
|
|
|
96
|
10
|
100
|
|
|
|
43
|
if ($t eq '<') { |
|
|
50
|
|
|
|
|
|
97
|
7
|
|
|
|
|
57
|
$sub .= " \$tr $ch~ /$reg\$/ and "; |
98
|
|
|
|
|
|
|
} elsif ($t eq '>') { |
99
|
3
|
|
|
|
|
10
|
$sub .= " /^$r[0](?$ch$reg)/ and "; |
100
|
|
|
|
|
|
|
} else { |
101
|
0
|
|
|
|
|
0
|
carp "Strange condition: " . join(' ', @$i), "\n"; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
34
|
|
|
|
|
131
|
$sub .= " s/^$r[0]// and \$tr .= '$r[1]' and next;\n"; |
105
|
34
|
|
|
|
|
72
|
@cond = (); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
8
|
|
|
|
|
47
|
$sub .= " s/^(.|\\n)//; \$tr .= \$1;\n }\nreturn \$tr;\n"; |
109
|
|
|
|
|
|
|
|
110
|
8
|
|
|
|
|
35
|
$self->{SUB} = $sub; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub transcribe { |
114
|
7
|
|
|
7
|
0
|
1087
|
my $self = shift; |
115
|
|
|
|
|
|
|
|
116
|
7
|
|
|
|
|
35
|
local ($_) = shift; |
117
|
7
|
|
|
|
|
2097
|
eval $self->{SUB}; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub generated_code { |
121
|
1
|
|
|
1
|
0
|
167
|
my $self = shift; |
122
|
|
|
|
|
|
|
|
123
|
1
|
|
|
|
|
6
|
return $self->{SUB}; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |
127
|
|
|
|
|
|
|
__END__ |