-
Notifications
You must be signed in to change notification settings - Fork 1
/
OxfordDictionary.pm
38 lines (31 loc) · 974 Bytes
/
OxfordDictionary.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package OxfordDictionary;
use strict;
use v5.10;
use Exporter;
use Module::Load;
our $VERSION = 0.01;
our @ISA = qw(Exporter);
our @keywords = qw(define);
our @EXPORT = qw(init needs);
sub define {
autoload "LWP::Simple";
autoload "XML::Twig";
autoload "HTML::Strip";
my $query = "\"" . join(" ", @_) . "\"";
my $html_strip = HTML::Strip->new();
my $twig = XML::Twig->new(twig_handlers => {
"sru_dc:dc" => sub {
my ($xml, $thing) = @_;
binmode(STDOUT, ":utf8");
say (($thing->first_child_text('dc:title')) . ":");
say ($html_strip->parse($thing->first_child_text('dc:description')));
}});
$twig->parse(get("http://www.oed.com/srupage?operation=searchRetrieve&query=cql.serverChoice+=+" . $query . "&maximumRecords=100&startRecord=1"));
}
sub init {
my $hashref = shift;
$hashref->{"define"} = \&OxfordDictionary::define;
}
sub needs {
return qw(LWP::Simple XML::Twig HTML::Strip);
}