line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Convert::yEnc; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23403
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
881
|
use IO::File; |
|
1
|
|
|
|
|
9984
|
|
|
1
|
|
|
|
|
150
|
|
5
|
1
|
|
|
1
|
|
666
|
use Convert::yEnc::Decoder; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
6
|
1
|
|
|
1
|
|
468
|
use Convert::yEnc::RC; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
25
|
|
7
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
608
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '1.06'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new |
13
|
|
|
|
|
|
|
{ |
14
|
6
|
|
|
6
|
1
|
151084
|
my($package, %params) = @_; |
15
|
|
|
|
|
|
|
|
16
|
6
|
|
66
|
|
|
31
|
my $rcFile = $params{RC } || "$ENV{HOME}/.yencrc"; |
17
|
6
|
|
100
|
|
|
25
|
my $outDir = $params{out} || '.'; |
18
|
6
|
|
66
|
|
|
35
|
my $tmpDir = $params{tmp} || $outDir; |
19
|
6
|
|
|
|
|
46
|
my $RC = new Convert::yEnc::RC $rcFile; |
20
|
6
|
|
|
|
|
46
|
my $decoder = new Convert::yEnc::Decoder; |
21
|
|
|
|
|
|
|
|
22
|
6
|
|
|
|
|
29
|
my $yEnc = { rcFile => $rcFile, |
23
|
|
|
|
|
|
|
RC => $RC, |
24
|
|
|
|
|
|
|
out => $outDir, |
25
|
|
|
|
|
|
|
tmp => $tmpDir, |
26
|
|
|
|
|
|
|
decoder => $decoder }; |
27
|
|
|
|
|
|
|
|
28
|
6
|
|
|
|
|
29
|
bless $yEnc, $package |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub out_dir |
33
|
|
|
|
|
|
|
{ |
34
|
0
|
|
|
0
|
1
|
0
|
my($yEnc, $dir) = @_; |
35
|
0
|
|
|
|
|
0
|
$yEnc->{out} = $dir; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub tmp_dir |
39
|
|
|
|
|
|
|
{ |
40
|
0
|
|
|
0
|
1
|
0
|
my($yEnc, $dir) = @_; |
41
|
0
|
|
|
|
|
0
|
$yEnc->{tmp} = $dir; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub decode |
46
|
|
|
|
|
|
|
{ |
47
|
8
|
|
|
8
|
1
|
1351
|
my($yEnc, $in) = @_; |
48
|
|
|
|
|
|
|
|
49
|
8
|
|
|
|
|
26
|
my $tmpDir = $yEnc->{tmp}; |
50
|
8
|
|
|
|
|
14
|
my $decoder = $yEnc->{decoder}; |
51
|
8
|
|
|
|
|
25
|
$decoder->out_dir($tmpDir); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
eval |
54
|
8
|
|
|
|
|
13
|
{ |
55
|
8
|
|
|
|
|
25
|
$decoder->decode($in); |
56
|
|
|
|
|
|
|
|
57
|
6
|
|
|
|
|
12
|
my $rc = $yEnc->{RC}; |
58
|
|
|
|
|
|
|
|
59
|
6
|
|
|
|
|
13
|
for my $tag (qw(ybegin ypart yend)) |
60
|
|
|
|
|
|
|
{ |
61
|
18
|
|
|
|
|
59
|
my $line = $decoder->$tag; |
62
|
18
|
100
|
|
|
|
40
|
$line or next; |
63
|
|
|
|
|
|
|
|
64
|
14
|
50
|
|
|
|
43
|
$rc->update($line) or |
65
|
|
|
|
|
|
|
die ref $yEnc, ": bad =$tag line: $line\n"; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
6
|
|
|
|
|
22
|
my $name = $decoder->name; |
69
|
6
|
100
|
|
|
|
24
|
$rc->complete($name) and |
70
|
|
|
|
|
|
|
$yEnc->_complete($name); |
71
|
|
|
|
|
|
|
}; |
72
|
|
|
|
|
|
|
|
73
|
8
|
|
|
|
|
40
|
my $err = $@; |
74
|
8
|
100
|
|
|
|
29
|
my $ok = $err ? 0 : 1; |
75
|
8
|
100
|
|
|
|
33
|
wantarray ? ($ok, $err) : $ok; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _complete |
79
|
|
|
|
|
|
|
{ |
80
|
5
|
|
|
5
|
|
25
|
my($yEnc, $name) = @_; |
81
|
|
|
|
|
|
|
|
82
|
5
|
|
|
|
|
18
|
$yEnc->{RC}->drop($name); |
83
|
|
|
|
|
|
|
|
84
|
5
|
|
|
|
|
10
|
my $tmpDir = $yEnc->{tmp}; |
85
|
5
|
|
|
|
|
7
|
my $outDir = $yEnc->{out}; |
86
|
|
|
|
|
|
|
|
87
|
5
|
|
|
|
|
10
|
my $tmpFile = "$tmpDir/$name"; |
88
|
5
|
|
|
|
|
17
|
my $outFile = $yEnc->mkpath($outDir, $name); |
89
|
|
|
|
|
|
|
|
90
|
5
|
100
|
100
|
|
|
184
|
if (defined $outFile and $outFile eq $tmpFile) |
|
|
100
|
|
|
|
|
|
91
|
|
|
|
|
|
|
{ |
92
|
|
|
|
|
|
|
# all done |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
elsif (defined $outFile) |
95
|
|
|
|
|
|
|
{ |
96
|
2
|
50
|
|
|
|
396
|
rename $tmpFile, $outFile or |
97
|
|
|
|
|
|
|
die ref $yEnc, ": Can't rename $tmpFile -> $outFile: $!\n"; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
else |
100
|
|
|
|
|
|
|
{ |
101
|
1
|
|
|
|
|
65
|
unlink $tmpFile; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub mkpath |
106
|
|
|
|
|
|
|
{ |
107
|
4
|
|
|
4
|
1
|
8
|
my($yEnc, $dir, $name) = @_; |
108
|
4
|
|
|
|
|
12
|
"$dir/$name" |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
0
|
0
|
0
|
sub decoder { shift->{decoder} } |
113
|
0
|
|
|
0
|
1
|
0
|
sub RC { shift->{RC } } |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub DESTROY |
117
|
|
|
|
|
|
|
{ |
118
|
6
|
|
|
6
|
|
5468
|
my $yEnc = shift; |
119
|
6
|
|
|
|
|
12
|
my $RC = $yEnc->{RC}; |
120
|
6
|
50
|
|
|
|
32
|
defined $RC and $RC->save; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1 |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |