Skip to content

Commit 77c6089

Browse files
committed
Use Try::Tiny (and namespace::autoclean)
no reason not to
1 parent eae45a4 commit 77c6089

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

dist.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Template::Plugin::JSON = 0
4040
Template::Plugin::Markdown = 0
4141
Template::Plugin::Number::Format = 0
4242
Template::Plugin::Page = 0
43+
Try::Tiny = 0.09
4344
XML::Feed = 0
4445
[Prereqs / TestRequires]
4546
Test::More = 0.96

lib/MetaCPAN/Web/Model/API.pm

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use Encode ();
99
use Test::More;
1010
use JSON;
1111
use AnyEvent::HTTP qw(http_request);
12+
use Try::Tiny 0.09;
13+
use namespace::autoclean;
1214

1315
{
1416
no warnings 'once';
@@ -87,12 +89,13 @@ sub raw_api_response {
8789

8890
# we have to assume an encoding; doing nothing is like assuming latin1
8991
# we'll probably have the least number of issues if we assume utf8
90-
local $@;
91-
eval {
92+
try {
9293
# decode so the template doesn't double-encode and return mojibake
9394
$data &&= $encoding->decode( $data, $encode_check );
95+
}
96+
catch {
97+
warn $_[0];
9498
};
95-
warn $@ if $@;
9699

97100
return +{ raw => $data };
98101
}

0 commit comments

Comments
 (0)