line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Dict::Zdic; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
121774
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
134
|
|
4
|
4
|
|
|
4
|
|
22
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
217
|
|
5
|
4
|
|
|
4
|
|
83
|
use v5.8.0; |
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
290
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.0.4'; |
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
23
|
use base 'WWW::Dict'; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
3192
|
|
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
5739
|
use WWW::Mechanize; |
|
4
|
|
|
|
|
838183
|
|
|
4
|
|
|
|
|
175
|
|
11
|
4
|
|
|
4
|
|
48
|
use Encode; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
443
|
|
12
|
4
|
|
|
4
|
|
25
|
use URI::Escape; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
257
|
|
13
|
4
|
|
|
4
|
|
4569
|
use HTML::TagParser; |
|
4
|
|
|
|
|
16813
|
|
|
4
|
|
|
|
|
183
|
|
14
|
4
|
|
|
4
|
|
33
|
use HTML::Entities; |
|
4
|
|
|
|
|
67
|
|
|
4
|
|
|
|
|
408
|
|
15
|
4
|
|
|
4
|
|
4026
|
use Class::Field qw'field const'; |
|
4
|
|
|
|
|
7488
|
|
|
4
|
|
|
|
|
2169
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Module implementation here |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
field ua => -init => 'WWW::Mechanize->new()'; |
20
|
|
|
|
|
|
|
const dict_url => 'http://www.zdic.net'; |
21
|
|
|
|
|
|
|
field word => ''; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub define { |
24
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
25
|
0
|
|
|
|
|
|
my $word = shift; |
26
|
0
|
|
|
|
|
|
$self->word($word); |
27
|
0
|
|
|
|
|
|
$word = URI::Escape::uri_escape_utf8($word); |
28
|
0
|
|
|
|
|
|
$word =~ s/%/Zdic/g; |
29
|
0
|
|
|
|
|
|
my $url = $self->dict_url . "/zd/zi/${word}.htm"; |
30
|
0
|
|
|
|
|
|
$self->ua->get($url); |
31
|
0
|
|
|
|
|
|
$self->parse_content( $self->ua->content() ); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub parse_content { |
35
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
36
|
0
|
|
|
|
|
|
my $html = HTML::TagParser->new; |
37
|
0
|
|
|
|
|
|
$html->parse(shift); |
38
|
0
|
|
|
|
|
|
my @def; |
39
|
0
|
|
|
|
|
|
for my $elem ( $html->getElementsByTagName("div") ) { |
40
|
0
|
|
|
|
|
|
my $attr = $elem->attributes; |
41
|
0
|
0
|
0
|
|
|
|
next unless ( 'tab-page' eq ( $attr->{class} || '' ) ); |
42
|
0
|
|
|
|
|
|
my $innerText = $elem->innerText; |
43
|
0
|
0
|
|
|
|
|
if (! Encode::is_utf8($innerText)) { |
44
|
0
|
|
|
|
|
|
$innerText = Encode::decode('utf8', $innerText); |
45
|
0
|
|
|
|
|
|
$innerText = decode_entities( $innerText ); |
46
|
|
|
|
|
|
|
} |
47
|
0
|
|
|
|
|
|
my @d = grep { !/tabPane|^\s*$/ } |
|
0
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
map { |
49
|
0
|
|
|
|
|
|
s/--.*?Zdic.net.*?--//g; |
50
|
0
|
|
|
|
|
|
s/\t//g; |
51
|
0
|
|
|
|
|
|
$_; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
split( /\r?\n/, $innerText ); |
54
|
0
|
|
|
|
|
|
push @def, |
55
|
|
|
|
|
|
|
{ |
56
|
|
|
|
|
|
|
category => $d[0], |
57
|
|
|
|
|
|
|
definition => join( "\n", @d[ 1 .. $#d ] ) |
58
|
|
|
|
|
|
|
}; |
59
|
|
|
|
|
|
|
} |
60
|
0
|
|
|
|
|
|
return \@def; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
64
|
|
|
|
|
|
|
__END__ |