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

33 lines
660 B
Perl
Raw Permalink Normal View History

2013-03-17 20:34:21 -07:00
package DDG::Goodie::Fortune;
# ABSTRACT: UNIX fortune quips.
2013-03-17 20:34:21 -07:00
use strict;
2013-03-17 20:34:21 -07:00
use DDG::Goodie;
use Fortune;
2014-10-14 11:52:56 -07:00
triggers startend => 'unix fortune', 'fortune cookie', 'random fortune';
2013-03-17 20:34:21 -07:00
zci answer_type => "fortune";
2014-10-14 11:52:56 -07:00
zci is_cached => 0;
2013-03-17 20:34:21 -07:00
2014-06-27 12:29:21 -07:00
my $ffile = share('fortunes');
my $fortune_file = Fortune->new($ffile);
$fortune_file->read_header();
2013-03-17 20:34:21 -07:00
handle remainder => sub {
my $output = $fortune_file->get_random_fortune();
2014-10-14 11:52:56 -07:00
$output =~ s/\n/ /g;
return $output, structured_answer => {
data => {
title => $output,
subtitle => "Random Fortune"
},
templates => {
group => 'text'
}
};
2013-03-17 20:34:21 -07:00
};
1;