line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Babelfish.pm,v 1.2 2003/09/03 15:11:03 cvspub Exp $ |
2
|
|
|
|
|
|
|
package PerlIO::via::Babelfish; |
3
|
1
|
|
|
1
|
|
10191
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
82
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $fish; |
7
|
|
|
|
|
|
|
our @setting_keys = qw(source target proxy agent); |
8
|
|
|
|
|
|
|
our %setting; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
943
|
use WWW::Babelfish; |
|
1
|
|
|
|
|
199709
|
|
|
1
|
|
|
|
|
520
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub import { |
13
|
1
|
|
|
1
|
|
10
|
shift; |
14
|
1
|
50
|
|
|
|
8
|
my $arg = ref($_[0]) ? $_[0] : {@_}; |
15
|
1
|
|
|
|
|
4
|
foreach my $s ( @setting_keys ){ |
16
|
4
|
|
|
|
|
10
|
$setting{$s} = $arg->{$s}; |
17
|
|
|
|
|
|
|
} |
18
|
1
|
|
50
|
|
|
9
|
$setting{agent} ||= 'Mozilla/8.0'; |
19
|
1
|
|
50
|
|
|
6
|
$setting{proxy} ||= 'proxy.ntu.edu.tw:3128'; |
20
|
1
|
|
|
|
|
6
|
$fish = new WWW::Babelfish( |
21
|
|
|
|
|
|
|
'agent' => $setting{agent}, |
22
|
|
|
|
|
|
|
'proxy' => $setting{proxy}, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub unimport { |
27
|
0
|
|
|
0
|
|
0
|
undef $fish; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub PUSHED { |
31
|
1
|
|
|
1
|
0
|
2552
|
my ($class,$mode,$fh) = @_; |
32
|
1
|
|
|
|
|
2
|
my $buf = ''; |
33
|
1
|
|
|
|
|
12
|
return bless \$buf,$class; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub FILL { |
37
|
0
|
|
|
0
|
0
|
0
|
my ($obj,$fh) = @_; |
38
|
0
|
|
|
|
|
0
|
my $line = <$fh>; |
39
|
0
|
0
|
0
|
|
|
0
|
if( ref($fish) and defined $line ){ |
40
|
0
|
|
|
|
|
0
|
return $fish->translate( |
41
|
|
|
|
|
|
|
'source' => $setting{source}, |
42
|
|
|
|
|
|
|
'destination' => $setting{target}, |
43
|
|
|
|
|
|
|
'text' => $line, |
44
|
|
|
|
|
|
|
'delimiter' => '', |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
else{ |
48
|
0
|
|
|
|
|
0
|
return undef; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub WRITE { |
53
|
1
|
|
|
1
|
|
9
|
my ($obj,$buf,$fh) = @_; |
54
|
1
|
|
|
|
|
1
|
my $bt; |
55
|
1
|
50
|
|
|
|
8
|
$$obj .= $bt = ref($fish) ? |
56
|
|
|
|
|
|
|
$fish->translate( |
57
|
|
|
|
|
|
|
'source' => $setting{source}, |
58
|
|
|
|
|
|
|
'destination' => $setting{target}, |
59
|
|
|
|
|
|
|
'text' => $buf, |
60
|
|
|
|
|
|
|
'delimiter' => '', |
61
|
|
|
|
|
|
|
) : |
62
|
|
|
|
|
|
|
$buf; |
63
|
1
|
|
|
|
|
5
|
$obj->FLUSH($fh); |
64
|
1
|
|
|
|
|
7
|
return length($bt); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub FLUSH { |
68
|
3
|
|
|
3
|
0
|
7
|
my ($obj,$fh) = @_; |
69
|
3
|
50
|
|
|
|
8
|
print $fh $$obj or return -1; |
70
|
3
|
|
|
|
|
6
|
$$obj = ''; |
71
|
3
|
|
|
|
|
18
|
return 0; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
__END__ |