#!/usr/bin/perl -X
my
$lang
=
$ENV
{MICRO_LANG} ||
"en"
;
my
$wiki
= WWW::Wikipedia->new(
language
=>
$lang
);
my
$memd
= new Cache::Memcached::Fast({
servers
=> [ {
address
=>
'localhost:11211'
,
weight
=> 2.5 }],
namespace
=>
'my:'
,
connect_timeout
=> 0.2,
io_timeout
=> 0.5,
close_on_error
=> 1,
compress_threshold
=> 100_000,
compress_ratio
=> 0.9,
compress_methods
=> [ \
&IO::Compress::Gzip::gzip
,
\
&IO::Uncompress::Gunzip::gunzip
],
max_failures
=> 3,
failure_timeout
=> 2,
ketama_points
=> 150,
nowait
=> 1,
hash_namespace
=> 1,
serialize_methods
=> [ \
&Storable::freeze
, \
&Storable::thaw
],
utf8
=> ($^V ge v5.8.1 ? 1 : 0),
max_size
=> 512 * 1024,
});
sub
decruft {
my
(
$file
) =
@_
;
my
(
$cruftSet
) =
q{%§&|#[^+*(]),'";}
;
my
$clean
=
$file
;
$clean
=~s/\Q
$_
//g
for
split
(
""
,
$cruftSet
);
return
$clean
;
}
sub
rel {
my
(
$arg
,
$lang
) =
@_
;
my
$result
=
$wiki
->search(
$arg
);
my
$str
=
""
;
if
(
defined
(
$result
) &&
$result
->text() ) {
$str
=
join
(
"\n"
,
$result
->related() );
}
return
$str
;
}
foreach
my
$call
(
@ARGV
)
{
my
$fromCache
=
$memd
->get(
$call
);
if
(
$fromCache
){
print
$fromCache
;
}
else
{
my
$str
= rel(
$call
,
$lang
);
$memd
->set(
$call
,
$str
);
}
}
1;