Created
January 18, 2014 23:45
-
-
Save brianmed/8498402 to your computer and use it in GitHub Desktop.
Mojo::JSON::j exception
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Mojo/JSON.pm b/lib/Mojo/JSON.pm | |
index cc5c6e3..1b83a27 100644 | |
--- a/lib/Mojo/JSON.pm | |
+++ b/lib/Mojo/JSON.pm | |
@@ -102,8 +102,22 @@ sub false {$FALSE} | |
sub j { | |
my $d = shift; | |
- return __PACKAGE__->new->encode($d) if ref $d eq 'ARRAY' || ref $d eq 'HASH'; | |
- return __PACKAGE__->new->decode($d); | |
+ my $json = __PACKAGE__->new; | |
+ | |
+ my $res; | |
+ if (ref $d eq 'ARRAY' || ref $d eq 'HASH') { | |
+ $res = $json->encode($d); | |
+ } | |
+ else { | |
+ $res = $json->decode($d); | |
+ } | |
+ | |
+ if ($json->error) { | |
+ die($json->error); | |
+ } | |
+ else { | |
+ return($res); | |
+ } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment