Skip to content

Commit

Permalink
pretty prints json if dump keyword provided - with colors if Data::Pr…
Browse files Browse the repository at this point in the history
…inter is installed
  • Loading branch information
tempire committed Jul 26, 2012
1 parent ec77b0e commit 72426f2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/Mojolicious/Command/get.pm
Expand Up @@ -9,6 +9,8 @@ use Mojo::JSON::Pointer;
use Mojo::UserAgent;
use Mojo::Util qw(decode encode);

eval 'use DDP alias => Dumper => colored => 1; 1' || eval 'use Data::Dumper';

has description => "Perform HTTP 1.1 request.\n";
has usage => <<"EOF";
usage: $0 get [OPTIONS] URL [SELECTOR|JSON-POINTER] [COMMANDS]
Expand Down Expand Up @@ -145,7 +147,11 @@ sub run {
sub _json {
my $json = Mojo::JSON->new;
return unless my $data = $json->decode(shift);
return unless defined($data = Mojo::JSON::Pointer->get($data, shift));

my $selector = shift;

return say(Dumper($data)) if $selector eq 'dump';
return unless defined($data = Mojo::JSON::Pointer->get($data, $selector));
ref $data ~~ [qw(HASH ARRAY)] ? say($json->encode($data)) : _say($data);
}

Expand Down

0 comments on commit 72426f2

Please sign in to comment.