GUID: add structured answer.

master
Matt Miller 2014-10-15 15:46:02 +02:00
parent 8c06d6deae
commit ddf99cd5a9
2 changed files with 31 additions and 48 deletions

View File

@ -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(<input type="text" onclick='this.select();' size="45" value="$guid"/>),
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;

View File

@ -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/^<input type="text" onclick='this.select\(\);' size="45" value="([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}"\/>$/,
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;