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

Commit

Permalink
Fortune: Moving the file loading out of the sub so it's only loaded once
Browse files Browse the repository at this point in the history
  • Loading branch information
mintsoft committed Jun 26, 2014
1 parent c91092f commit b8f896a
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";

our $ffile = share('fortunes');
our $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 b8f896a

Please sign in to comment.