Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 110 lines (78 sloc) 1.85 KB
#!/usr/bin/perl
use strict;
BEGIN {
our($VERSION);
$VERSION = '0.052';
};
use utf8;
use LWP::UserAgent;
use Getopt::Long;
use Pod::Usage;
use Encode;
use Net::Google::TLD qw(get_url_by_tld);
my %options = (
locale => 'com',
help => 0,
);
# Need -CA for utf8 ARGV support under(?) 5.8 or use decode
# Hmm...
my $query = decode('utf-8',$ARGV[0]) // 'insansiate';
our($opt_show_locales);
GetOptions(
'locale=s' => \$options{locale},
'show' => \$opt_show_locales,
'help|h' => sub { pod2usage(verbose => 1, exitval => 1,); },
);
my $used_rule = $options{locale};
my %rules = (
com => {
re => '<b><i>(.+)</i></b>',
},
es => {
re => '<b><i>(.+)</i></b>',
},
tw => {
re => '<em>(.+)</em>',
},
);
if($opt_show_locales) {
print "$_\n" for keys %rules;
exit;
}
map { $rules{$_}->{url} = 'http://' . (get_url_by_tld($_))[0] } keys %rules;
my $lwp = LWP::UserAgent->new(agent => 'Mozilla');
my $response = $lwp->get(
"$rules{ $options{locale} }->{url}/search?q=$query"
) or die $!;
if ($response->decoded_content =~ m[<a.*?class=spell>(.*?)</a>]s) {
if ($1 =~ m[$rules{$used_rule}->{re}]) {
print "$1\n";
exit;
}
}
__END__
=head1 NAME
typo - A tiny tool that can help you detect your typos in input
=head1 SYNOPSIS
typo [input] [-h|--help|--locale=your_locale]
=head1 OPTIONS
-l, --locale set prefered locale
-s, --show show available locales
-h, --help show the help and exit
=head1 AUTHOR
Magnus Woldrich
CPAN ID: WOLDRICH
magnus@trapd00r.se
http://japh.se
=head1 CONTRIBUTORS
EragonJ
eragonj@hax4.in
http://eragonj.hax4.in
=head1 COPYRIGHT
Copyright 2010, 2011 B<THIS MODULE>s L</AUTHOR> and L</CONTRIBUTORS> as listed
above.
=head1 LICENSE
This program is free software; you may redistribute it and/or modify it under
the same terms as Perl itself.
=cut
# vim: set ts=2 et sw=2: