From 6453b6e3969a28f9f0760d60b5a60dc3ffde11e2 Mon Sep 17 00:00:00 2001 From: Peter van Dijk Date: Thu, 7 Jun 2012 23:07:50 +0200 Subject: [PATCH] add IDN goodie --- dist.ini | 1 + lib/DDG/Goodie/IDN.pm | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 lib/DDG/Goodie/IDN.pm diff --git a/dist.ini b/dist.ini index a6fd5b539..6e43518cd 100644 --- a/dist.ini +++ b/dist.ini @@ -29,6 +29,7 @@ Convert::Color = 0.08 Convert::Color::Library = 0.03 Math::Round = 0.06 Convert::Morse = 0.05 +Net::IDN::Encode = 2.003 [Prereqs / TestRequires] Test::More = 0.98 diff --git a/lib/DDG/Goodie/IDN.pm b/lib/DDG/Goodie/IDN.pm new file mode 100644 index 000000000..593af734c --- /dev/null +++ b/lib/DDG/Goodie/IDN.pm @@ -0,0 +1,22 @@ +package DDG::Goodie::IDN; +# ABSTRACT: Convert domain names from/to Punycode. + +use DDG::Goodie; +use Net::IDN::Encode ':all'; +use HTML::Entities; + +triggers start => 'idn'; + +handle remainder => sub { + if(/^xn--/) { + return 'decoded IDN: '.encode_entities(domain_to_unicode($_)); + } + else { + return 'encoded IDN: '.encode_entities(domain_to_ascii($_)); + } + # return; +}; + +zci is_cached => 1; + +1; \ No newline at end of file