Skip to content

Commit

Permalink
fixed small encoding bug in get command
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Dec 23, 2011
1 parent eb1c2da commit 5869d29
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/Mojolicious/Command/get.pm
Expand Up @@ -147,18 +147,19 @@ sub run {
# JSON
return unless $selector;
return $self->_json($buffer, $selector)
if $tx->res->headers->content_type =~ /JSON/i;
if ($tx->res->headers->content_type || '') =~ /JSON/i;

# Selector
$self->_select($buffer, $charset // $tx->res->content->charset, $selector);
}

sub _json {
my ($self, $buffer, $pointer) = @_;
my $j = Mojo::JSON->new;
return unless my $data = $j->decode($buffer);
my $json = Mojo::JSON->new;
return unless my $data = $json->decode($buffer);
return unless $data = Mojo::JSON::Pointer->get($data, $pointer);
say ref $data eq 'HASH' || ref $data eq 'ARRAY' ? $j->encode($data) : $data;
ref $data eq 'HASH'
|| ref $data eq 'ARRAY' ? say($json->encode($data)) : _say($data);
}

sub _say {
Expand Down

0 comments on commit 5869d29

Please sign in to comment.