Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
simplified j function
  • Loading branch information
kraih committed Mar 22, 2013
1 parent 3887d86 commit b79a780
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/Mojo/JSON.pm
Expand Up @@ -2,10 +2,10 @@ package Mojo::JSON;
use Mojo::Base -base;

use B;
use Carp 'croak';
use Exporter 'import';
use Mojo::Util;
use Scalar::Util 'blessed';
use Carp 'croak';

has 'error';

Expand Down Expand Up @@ -107,10 +107,8 @@ sub false {$FALSE}
sub j {
my $d = shift;
my $json = __PACKAGE__->new;
my $res
= ref($d) =~ /^(?:ARRAY|HASH)$/ ? $json->encode($d) : $json->decode($d);
$res // croak($json->error);
return $res;
return $json->encode($d) if ref $d eq 'ARRAY' || ref $d eq 'HASH';
return $json->decode($d) // croak $json->error;
}

sub true {$TRUE}
Expand Down

0 comments on commit b79a780

Please sign in to comment.