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

Commit b4d1c58

Browse files
committed
Merge pull request #516 from duckduckgo/mintsoft/fortune
Fortune: Moving the file loading out of the sub so it's only loaded once
2 parents fc962e7 + 3e638e9 commit b4d1c58

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

lib/DDG/Goodie/Fortune.pm

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ attribution github => ['https://github.com/frncscgmz', 'frncscgmz'];
1616
zci is_cached => 0;
1717
zci answer_type => "fortune";
1818

19+
my $ffile = share('fortunes');
20+
my $fortune_file = Fortune->new($ffile);
21+
$fortune_file->read_header();
22+
1923
handle remainder => sub {
20-
my $ffile = share('fortunes');
21-
my $fortune_file = Fortune->new($ffile);
22-
$fortune_file->read_header();
23-
my $output = $fortune_file->get_random_fortune();
24-
$output =~ s/\n//g;
25-
return $output;
24+
my $output = $fortune_file->get_random_fortune();
25+
$output =~ s/\n//g;
26+
return $output;
2627
};
2728

2829
1;

t/Fortune.t

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ zci answer_type => 'fortune';
99
zci is_cached => 0;
1010

1111
ddg_goodie_test(
12-
[qw(
13-
DDG::Goodie::Fortune
14-
)],
15-
'gimmie a fortune cookie' => test_zci(qr/.+/),
12+
[qw(
13+
DDG::Goodie::Fortune
14+
)],
15+
'gimmie a fortune cookie' => test_zci(qr/.+/),
1616
'gimmie a unix fortune' => test_zci(qr/.+/),
17-
'give me a fortune cookie!' => test_zci(qr/.+/),
17+
'give me a fortune cookie!' => test_zci(qr/.+/),
1818
'give me a unix fortune!' => test_zci(qr/.+/),
1919
'unix fortune cookie' => test_zci(qr/.+/),
2020
);

0 commit comments

Comments
 (0)