commit
320a607b6e
2
dist.ini
2
dist.ini
|
@ -38,6 +38,7 @@ Email::Valid = 1.192
|
|||
Net::Domain::TLD = 1.70
|
||||
Convert::Pluggable = 0.021
|
||||
YAML = 0
|
||||
Encode = 2.62
|
||||
; ParseCron
|
||||
Schedule::Cron::Events = 0
|
||||
Convert::Color = 0.08
|
||||
|
@ -51,6 +52,7 @@ Acme::rafl::Everywhere = 0.008
|
|||
Lingua::EN::Numbers::Ordinate = 1.02
|
||||
; Hashes
|
||||
Digest::SHA = 5.82
|
||||
Digest::MD5 = 2.53
|
||||
; Factors
|
||||
Math::Prime::Util = 0.34
|
||||
Games::Sudoku::Component = 0.02
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package DDG::Goodie::MD5;
|
||||
# ABSTRACT: Calculate the MD5 digest of a string.
|
||||
|
||||
use DDG::Goodie;
|
||||
use Digest::MD5 qw(md5_base64 md5_hex);
|
||||
use Encode qw(encode);
|
||||
|
||||
zci answer_type => 'md5';
|
||||
zci is_cached => 1;
|
||||
|
||||
primary_example_queries 'md5 digest this!';
|
||||
secondary_example_queries 'duckduckgo md5',
|
||||
'md5sum the sum of a string';
|
||||
|
||||
name 'MD5';
|
||||
description 'Calculate the MD5 digest of a string.';
|
||||
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/MD5.pm';
|
||||
category 'transformations';
|
||||
|
||||
triggers startend => 'md5', 'md5sum';
|
||||
|
||||
my $css = share('style.css')->slurp;
|
||||
|
||||
sub html_output {
|
||||
my ($md5, $str) = @_;
|
||||
return "<style type='text/css'>$css</style>"
|
||||
."<div class='zci--md5'>"
|
||||
."<span class='text--secondary'>MD5 of \"$str\"</span><br/>"
|
||||
."<span class='text--primary'>$md5</span>"
|
||||
."</div>";
|
||||
}
|
||||
|
||||
handle remainder => sub {
|
||||
if (/^\s*(.*)\s*$/) {
|
||||
# Exit unless a string is found
|
||||
return unless $1;
|
||||
# The string is encoded to get the utf8 representation instead of
|
||||
# perls internal representation of strings, before it's passed to
|
||||
# the md5 subroutine.
|
||||
my $str = md5_hex (encode "utf8", $1);
|
||||
return $str, html => html_output ($str, $1);
|
||||
}
|
||||
};
|
||||
|
||||
1;
|
|
@ -0,0 +1,13 @@
|
|||
.zci--answer .zci--md5 {
|
||||
font-weight: 300;
|
||||
padding: .25em 0;
|
||||
}
|
||||
|
||||
.zci--md5 .text--primary {
|
||||
font-size: 1.5em;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
.zci--md5 .text--secondary {
|
||||
font-size: 1.1em;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
use DDG::Test::Goodie;
|
||||
|
||||
zci answer_type => 'md5';
|
||||
zci is_cached => 1;
|
||||
|
||||
ddg_goodie_test(
|
||||
[qw(
|
||||
DDG::Goodie::MD5
|
||||
)],
|
||||
'md5 digest this!' => test_zci('3838c8fb10a114e6d21203359ef147ad', html=>qr/.*/),
|
||||
'duckduckgo md5' => test_zci('96898bb8544fa56b03c08cdc09886c6c', html=>qr/.*/),
|
||||
'md5sum the sum of a string' => test_zci('a704c8833f9850cd342ead27207ca1a1', html=>qr/.*/),
|
||||
);
|
||||
|
||||
done_testing;
|
Loading…
Reference in New Issue