zeroclickinfo-goodies/lib/DDG/Goodie/URLEncode.pm

45 lines
1.4 KiB
Perl
Raw Normal View History

package DDG::Goodie::URLEncode;
# ABSTRACT: Displays the percent-encoded url.
use DDG::Goodie;
2014-06-24 19:29:03 -07:00
use URI::Escape::XS qw(encodeURIComponent);
use warnings;
use strict;
2014-06-24 19:29:03 -07:00
triggers startend => 'url encode', 'encode url', 'urlencode', 'encodeurl', 'url escape', 'escape url', 'urlescape', 'escapeurl';
primary_example_queries 'url encode https://duckduckgo.com/' , 'encode url xkcd.com/blag';
secondary_example_queries 'http://arstechnica.com/ url escape', 'apple.com/mac/ escape url';
zci answer_type => 'encoded_url';
zci is_cached => 1;
2014-06-24 19:29:03 -07:00
name 'URLEncode';
2014-06-24 19:29:03 -07:00
description 'Displays the percent-encoded url';
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/URLEncode.pm';
category 'computing_tools';
topics 'programming', 'web_design';
attribution twitter => ['nshanmugham', 'Nishanth Shanmugham'],
web => ['http://nishanths.github.io', 'Nishanth Shanmugham'],
github => ['nishanths', 'Nishanth Shanmugham'];
handle remainder => sub {
2014-10-10 03:01:58 -07:00
my $in = $_;
return unless $in;
my $encoded_url = encodeURIComponent($in);
my $text = "Percent-encoded URL: $encoded_url";
2014-10-10 03:01:58 -07:00
return $text,
structured_answer => {
input => [html_enc($in)],
operation => 'URL percent-encode',
result => html_enc($encoded_url),
};
};
1;