line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dictionary::Cambridge::Response; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:JINNKS'; |
3
|
|
|
|
|
|
|
#ABSTRACT: the roles to parse different part of the xml returned |
4
|
|
|
|
|
|
|
$Dictionary::Cambridge::Response::VERSION = '0.02'; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1227
|
use Moose::Role; |
|
1
|
|
|
|
|
4616
|
|
|
1
|
|
|
|
|
5
|
|
7
|
1
|
|
|
1
|
|
5910
|
use XML::LibXML; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use namespace::autoclean; |
9
|
|
|
|
|
|
|
use List::MoreUtils qw( zip ); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has "xml" => ( |
12
|
|
|
|
|
|
|
is => 'ro', |
13
|
|
|
|
|
|
|
isa => 'XML::LibXML', |
14
|
|
|
|
|
|
|
lazy_build => 1 |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _build_xml { |
18
|
|
|
|
|
|
|
return XML::LibXML->new(); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub parse_xml_def_eg { |
23
|
|
|
|
|
|
|
my ( $self, $xml_data ) = @_; |
24
|
|
|
|
|
|
|
my $doc = $self->xml->load_xml( string => $xml_data ); |
25
|
|
|
|
|
|
|
my %definition = (); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my @pos_blocks = $doc->findnodes( '//di/pos-block' ); |
28
|
|
|
|
|
|
|
for my $pos_block (@pos_blocks) { |
29
|
|
|
|
|
|
|
my $pos = $pos_block->findvalue( './header/info/posgram/pos' ); |
30
|
|
|
|
|
|
|
my @defs = $pos_block->findnodes( './sense-block/def-block' ); |
31
|
|
|
|
|
|
|
for my $d( @defs ) { |
32
|
|
|
|
|
|
|
my $def = $d->findvalue('./definition/def'); |
33
|
|
|
|
|
|
|
my @eg = map { $_->string_value() } $d->findnodes('./examp/eg'); |
34
|
|
|
|
|
|
|
push @{$definition{$pos}},{"definition" => $def, "example" => \@eg}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
return \%definition; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
__END__ |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=pod |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=encoding UTF-8 |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 NAME |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Dictionary::Cambridge::Response - the roles to parse different part of the xml returned |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 VERSION |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
version 0.02 |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 METHODS |
57
|
|
|
|
|
|
|
parse_xml_def_eg |
58
|
|
|
|
|
|
|
params: xml content of the API get_entry call |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 AUTHOR |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Farhan Siddiqui <forsadia@gmail.com> |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Farhan Siddiqui. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
69
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |