Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #516 from duckduckgo/mintsoft/fortune
Browse files Browse the repository at this point in the history
Fortune: Moving the file loading out of the sub so it's only loaded once
  • Loading branch information
mwmiller committed Jun 28, 2014
2 parents fc962e7 + 3e638e9 commit b4d1c58
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
13 changes: 7 additions & 6 deletions lib/DDG/Goodie/Fortune.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ attribution github => ['https://github.com/frncscgmz', 'frncscgmz'];
zci is_cached => 0;
zci answer_type => "fortune";

my $ffile = share('fortunes');
my $fortune_file = Fortune->new($ffile);
$fortune_file->read_header();

handle remainder => sub {
my $ffile = share('fortunes');
my $fortune_file = Fortune->new($ffile);
$fortune_file->read_header();
my $output = $fortune_file->get_random_fortune();
$output =~ s/\n//g;
return $output;
my $output = $fortune_file->get_random_fortune();
$output =~ s/\n//g;
return $output;
};

1;
10 changes: 5 additions & 5 deletions t/Fortune.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ zci answer_type => 'fortune';
zci is_cached => 0;

ddg_goodie_test(
[qw(
DDG::Goodie::Fortune
)],
'gimmie a fortune cookie' => test_zci(qr/.+/),
[qw(
DDG::Goodie::Fortune
)],
'gimmie a fortune cookie' => test_zci(qr/.+/),
'gimmie a unix fortune' => test_zci(qr/.+/),
'give me a fortune cookie!' => test_zci(qr/.+/),
'give me a fortune cookie!' => test_zci(qr/.+/),
'give me a unix fortune!' => test_zci(qr/.+/),
'unix fortune cookie' => test_zci(qr/.+/),
);
Expand Down

0 comments on commit b4d1c58

Please sign in to comment.