This repository was archived by the owner on Oct 15, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +80
-0
lines changed Expand file tree Collapse file tree 4 files changed +80
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ Email::Valid = 1.192
3838Net::Domain::TLD = 1.70
3939Convert::Pluggable = 0.021
4040YAML = 0
41+ Encode = 2.62
4142; ParseCron
4243Schedule::Cron::Events = 0
4344Convert::Color = 0.08
@@ -51,6 +52,7 @@ Acme::rafl::Everywhere = 0.008
5152Lingua::EN::Numbers::Ordinate = 1.02
5253; Hashes
5354Digest::SHA = 5.82
55+ Digest::MD5 = 2.53
5456; Factors
5557Math::Prime::Util = 0.34
5658Games::Sudoku::Component = 0.02
Original file line number Diff line number Diff line change 1+ package DDG::Goodie::MD5 ;
2+ # ABSTRACT: Calculate the MD5 digest of a string.
3+
4+ use DDG::Goodie;
5+ use Digest::MD5 qw( md5_base64 md5_hex) ;
6+ use Encode qw( encode) ;
7+
8+ zci answer_type => ' md5' ;
9+ zci is_cached => 1;
10+
11+ primary_example_queries ' md5 digest this!' ;
12+ secondary_example_queries ' duckduckgo md5' ,
13+ ' md5sum the sum of a string' ;
14+
15+ name ' MD5' ;
16+ description ' Calculate the MD5 digest of a string.' ;
17+ code_url ' https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/MD5.pm' ;
18+ category ' transformations' ;
19+
20+ triggers startend => ' md5' , ' md5sum' ;
21+
22+ my $css = share(' style.css' )-> slurp;
23+
24+ sub html_output {
25+ my ($md5 , $str ) = @_ ;
26+ return " <style type='text/css'>$css </style>"
27+ ." <div class='zci--md5'>"
28+ ." <span class='text--secondary'>MD5 of \" $str \" </span><br/>"
29+ ." <span class='text--primary'>$md5 </span>"
30+ ." </div>" ;
31+ }
32+
33+ handle remainder => sub {
34+ if (/ ^\s *(.*)\s *$ / ) {
35+ # Exit unless a string is found
36+ return unless $1 ;
37+ # The string is encoded to get the utf8 representation instead of
38+ # perls internal representation of strings, before it's passed to
39+ # the md5 subroutine.
40+ my $str = md5_hex (encode " utf8" , $1 );
41+ return $str , html => html_output ($str , $1 );
42+ }
43+ };
44+
45+ 1;
Original file line number Diff line number Diff line change 1+ .zci--answer .zci--md5 {
2+ font-weight : 300 ;
3+ padding : .25em 0 ;
4+ }
5+
6+ .zci--md5 .text--primary {
7+ font-size : 1.5em ;
8+ word-wrap : break-word;
9+ }
10+
11+ .zci--md5 .text--secondary {
12+ font-size : 1.1em ;
13+ }
Original file line number Diff line number Diff line change 1+ # !/usr/bin/env perl
2+
3+ use strict;
4+ use warnings;
5+ use Test::More;
6+ use DDG::Test::Goodie;
7+
8+ zci answer_type => ' md5' ;
9+ zci is_cached => 1;
10+
11+ ddg_goodie_test(
12+ [qw(
13+ DDG::Goodie::MD5
14+ ) ],
15+ ' md5 digest this!' => test_zci(' 3838c8fb10a114e6d21203359ef147ad' , html => qr / .*/ ),
16+ ' duckduckgo md5' => test_zci(' 96898bb8544fa56b03c08cdc09886c6c' , html => qr / .*/ ),
17+ ' md5sum the sum of a string' => test_zci(' a704c8833f9850cd342ead27207ca1a1' , html => qr / .*/ ),
18+ );
19+
20+ done_testing;
You can’t perform that action at this time.
0 commit comments