Skip to content

Commit

Permalink
another small optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 19, 2014
1 parent 57695bc commit 818d5a7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,7 +1,7 @@

4.82 2014-02-19
- Added data attribute to Mojo::JSON::Pointer.
- Added decode_json and encode_json functions to Mojo::JSON.
- Added data attribute to Mojo::JSON::Pointer.
- Fixed small decoding error bug in Mojo::JSON.
- Fixed bug in "user_agent_online.t".

Expand Down
8 changes: 3 additions & 5 deletions lib/Mojo/JSON.pm
Expand Up @@ -52,10 +52,9 @@ sub decode {
}

sub decode_json {
my $bytes = shift;

# Missing input
die "Missing or empty input\n" unless length $bytes;
die "Missing or empty input\n" unless length(my $bytes = shift);

# Remove BOM
$bytes =~ s/^(?:\357\273\277|\377\376\0\0|\0\0\376\377|\376\377|\377\376)//g;
Expand Down Expand Up @@ -97,9 +96,8 @@ sub encode_json { Mojo::Util::encode 'UTF-8', _encode_value(shift) }
sub false {$FALSE}

sub j {
my $data = shift;
return encode_json($data) if ref $data eq 'ARRAY' || ref $data eq 'HASH';
return eval { decode_json($data) };
return encode_json($_[0]) if ref $_[0] eq 'ARRAY' || ref $_[0] eq 'HASH';
return eval { decode_json($_[0]) };
}

sub true {$TRUE}
Expand Down

0 comments on commit 818d5a7

Please sign in to comment.