Skip to content

Commit

Permalink
small tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 19, 2013
1 parent 47274a8 commit 6ecadc2
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions lib/Mojolicious/Command/get.pm
Expand Up @@ -117,8 +117,8 @@ sub run {
return $self->_json($buffer, $selector) if $type =~ /json/i;

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

sub _json {
Expand All @@ -127,11 +127,12 @@ sub _json {
my $json = Mojo::JSON->new;
return unless my $data = $json->decode(shift);
return unless defined($data = Mojo::JSON::Pointer->new->get($data, shift));
return say $self->auto_encode($data)
unless ref $data eq 'HASH' || ref $data eq 'ARRAY';
say $self->auto_encode(decode 'UTF-8', $json->encode($data));
return $self->_say($data) unless ref $data eq 'HASH' || ref $data eq 'ARRAY';
$self->_say(decode 'UTF-8', $json->encode($data));
}

sub _say { say shift->auto_encode(@)) }

sub _select {
my ($self, $buffer, $selector, $charset, @args) = @_;

Expand All @@ -148,19 +149,15 @@ sub _select {
}

# Text
elsif ($command eq 'text') {
say $self->auto_encode($_->text) for @$results;
}
elsif ($command eq 'text') { $self->_say($_->text) for @$results }

# All text
elsif ($command eq 'all') {
say $self->auto_encode($_->all_text) for @$results;
}
elsif ($command eq 'all') { $self->_say($_->all_text) for @$results }

# Attribute
elsif ($command eq 'attr') {
next unless my $name = shift @args;
say $self->auto_encode($_->attrs->{$name}) for @$results;
$self->_say($_->attrs->{$name}) for @$results;
}

# Unknown
Expand Down

0 comments on commit 6ecadc2

Please sign in to comment.