2012-06-07 14:07:50 -07:00
|
|
|
package DDG::Goodie::IDN;
|
|
|
|
# ABSTRACT: Convert domain names from/to Punycode.
|
|
|
|
|
|
|
|
use DDG::Goodie;
|
|
|
|
use Net::IDN::Encode ':all';
|
|
|
|
use HTML::Entities;
|
2012-11-06 10:11:23 -08:00
|
|
|
use utf8;
|
2012-06-07 14:07:50 -07:00
|
|
|
|
2012-11-06 10:11:23 -08:00
|
|
|
primary_example_queries => 'idn exämple.com';
|
|
|
|
secondary_example_queries => 'idn xn--exmple-cua.com';
|
|
|
|
description 'encode and decode internationalized domain names';
|
|
|
|
name 'IDN';
|
|
|
|
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/IDN.pm';
|
|
|
|
topics => 'computing_tools';
|
|
|
|
categories => 'travel';
|
2012-07-06 09:26:06 -07:00
|
|
|
attribution web => ['http://7bits.nl/', 'Peter van Dijk'],
|
|
|
|
email => ['peter@7bits.nl', 'Peter van Dijk'],
|
|
|
|
github => ['https://github.com/habbie', 'habbie'],
|
|
|
|
twitter => ['https://twitter.com/habbie', 'habbie'];
|
2012-07-05 23:06:30 -07:00
|
|
|
|
2012-07-06 12:42:14 -07:00
|
|
|
triggers startend => 'idn', 'international domain', 'internationalized domain';
|
2012-06-07 14:07:50 -07:00
|
|
|
|
2012-07-06 12:43:46 -07:00
|
|
|
handle query_lc => sub {
|
2012-07-08 10:58:55 -07:00
|
|
|
return unless s/(international(?:ized)? domain(?: name)?|idn) //;
|
|
|
|
my $idn = ($1 eq "idn" ? uc $1 : $1) . ": ";
|
|
|
|
return unless m/\.(ac|ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|asia|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cat|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cu|cv|cw|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|info|int|io|iq|ir|is|it|je|jm|jo|jobs|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|local|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mo|mobi|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sx|sy|sz|tc|td|tel|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|travel|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|xxx|ye|yt|za|zm|zw)$/i;
|
2012-06-07 14:07:50 -07:00
|
|
|
if(/^xn--/) {
|
2012-07-06 12:43:46 -07:00
|
|
|
return 'Decoded ' . $idn . encode_entities(domain_to_unicode($_));
|
2012-06-07 14:07:50 -07:00
|
|
|
}
|
|
|
|
else {
|
2012-07-06 12:43:46 -07:00
|
|
|
return 'Encoded ' . $idn . encode_entities(domain_to_ascii($_));
|
2012-06-07 14:07:50 -07:00
|
|
|
}
|
2012-07-06 10:44:00 -07:00
|
|
|
return;
|
2012-06-07 14:07:50 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
zci is_cached => 1;
|
|
|
|
|
2012-07-05 23:06:30 -07:00
|
|
|
1;
|