From ddf99cd5a935d3f67924fd3c10f815d6c0c267e7 Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Wed, 15 Oct 2014 15:46:02 +0200 Subject: [PATCH] GUID: add structured answer. --- lib/DDG/Goodie/GUID.pm | 44 +++++++++++++++++++++++------------------- t/GUID.t | 35 +++++++-------------------------- 2 files changed, 31 insertions(+), 48 deletions(-) diff --git a/lib/DDG/Goodie/GUID.pm b/lib/DDG/Goodie/GUID.pm index b4c17779f..d66f21fff 100644 --- a/lib/DDG/Goodie/GUID.pm +++ b/lib/DDG/Goodie/GUID.pm @@ -4,10 +4,18 @@ package DDG::Goodie::GUID; use DDG::Goodie; use Data::GUID; -triggers start => 'globally', 'universally', 'rfc', 'guid', 'uuid'; +my %guid = ( + 'guid' => 0, + 'uuid' => 1, + 'globally unique identifier' => 0, + 'universally unique identifier' => 1, + 'rfc 4122' => 0, +); + +triggers start => keys %guid; zci answer_type => "guid"; -zci is_cached => 0; +zci is_cached => 0; primary_example_queries 'guid'; secondary_example_queries 'uuid'; @@ -17,27 +25,23 @@ code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DD category 'computing_tools'; topics 'programming'; attribution twitter => 'crazedpsyc', - cpan => 'CRZEDPSYC' , + cpan => 'CRZEDPSYC', twitter => 'loganmccamon', - github => 'loganom'; + github => 'loganom'; -my %guid = ( - 'guid' => 0, - 'uuid' => 1, - 'globally unique identifier' => 0, - 'universally unique identifier' => 1, - 'rfc 4122' => 0, - ); -handle query_lc => sub { - return unless exists $guid{$_}; - if (my $guid = Data::GUID->new) { - my $guid_string = $guid->as_string; +handle remainder => sub { - return answer => $guid_string, - html => qq(), - heading => 'Random GUID'; - } - return; + my $guid = Data::GUID->new; + + return unless $guid; + + return $guid->as_string, + structured_answer => { + input => [], + operation => 'random GUID', + result => $guid->as_string + }; }; + 1; diff --git a/t/GUID.t b/t/GUID.t index 7ce9720e0..b132e32d9 100644 --- a/t/GUID.t +++ b/t/GUID.t @@ -8,36 +8,15 @@ use DDG::Test::Goodie; zci answer_type => 'guid'; zci is_cached => 0; -my $heading = 'Random GUID'; +my @answer = (qr/^([a-zA-Z]|\d){8}-([a-zA-Z]|\d){4}-([a-zA-Z]|\d){4}-([a-zA-Z]|\d){4}-([a-zA-Z]|\d){12}$/, structured_answer => { input =>[], operation => 'random GUID', result =>qr/^([a-zA-Z]|\d){8}-([a-zA-Z]|\d){4}-([a-zA-Z]|\d){4}-([a-zA-Z]|\d){4}-([a-zA-Z]|\d){12}$/}); -ddg_goodie_test( - [qw( - DDG::Goodie::GUID - )], +ddg_goodie_test([qw( DDG::Goodie::GUID ) ], - # Check that the trigger kicks in. - 'guid' => test_zci(qr/^([a-zA-Z]|\d){8}-([a-zA-Z]|\d){4}-([a-zA-Z]|\d){4}-([a-zA-Z]|\d){4}-([a-zA-Z]|\d){12}$/, - html => qr/./, - heading => $heading - ), - 'uuid' => test_zci(qr/^([a-zA-Z]|\d){8}-([a-zA-Z]|\d){4}-([a-zA-Z]|\d){4}-([a-zA-Z]|\d){4}-([a-zA-Z]|\d){12}$/, - html => qr/./, - heading => $heading - ), - 'globally unique identifier' => test_zci(qr/^([a-zA-Z]|\d){8}-([a-zA-Z]|\d){4}-([a-zA-Z]|\d){4}-([a-zA-Z]|\d){4}-([a-zA-Z]|\d){12}$/, - html => qr/./, - heading => $heading - ), - 'rfc 4122' => test_zci(qr/^([a-zA-Z]|\d){8}-([a-zA-Z]|\d){4}-([a-zA-Z]|\d){4}-([a-zA-Z]|\d){4}-([a-zA-Z]|\d){12}$/, - html => qr/./, - heading => $heading - ), - - # Check the HTML. Just once. - 'guid' => test_zci(qr/^([a-zA-Z]|\d){8}-([a-zA-Z]|\d){4}-([a-zA-Z]|\d){4}-([a-zA-Z]|\d){4}-([a-zA-Z]|\d){12}$/, - html => qr/^$/, - heading => $heading - ), + # Check that the trigger kicks in. + 'guid' => test_zci(@answer), + 'uuid' => test_zci(@answer), + 'globally unique identifier' => test_zci(@answer), + 'rfc 4122' => test_zci(@answer), ); done_testing;