age App::PAIA::JSON;
use strict;
use v5.10;
our $VERSION = '0.30';
use parent 'Exporter';
our @EXPORT = qw(decode_json encode_json);
use JSON::PP qw();
sub decode_json {
my $json = shift;
m
y $data = eval { JSON::PP->new->utf8->relaxed->decode($json); };
if ($@) {
my $msg = reverse $@;
$msg =~ s/.+? ta //sm;
$msg = "JSON error: " . scalar reverse($msg);
return $data;
}
sub encode_json {
JSON::PP->new->utf8->pretty->encode($_[0]);
}
1;
__END__
=head1 NAME
App::PAIA::JSON - utility functions to encode/decode JSON
=head1 DESCRIPTION
This mo
;
use strict;
use v5.10;
use parent 'App::PAIA::Command';
our $VERSION = '0.30';
use App::PAIA::JSON;
sub _execute {
my ($self, $opt, $args) = @_;
$self->core_request('GET', 'items');
}
1
ict;
use v5.10;
our $VERSION = '0.30';
use App::PAIA::JSON;
our %DEFAULT = (
'config' => 'paia.json',
'session' => 'paia-session.json'
);
sub new {
my $class = shift;
my $self = b
$fh, '<', $file)
or die "failed to open $type file $file\n";
$self->{data} = decode_json(<$fh>,$file);
close $fh;
$self->{logger}->("loaded $type file $file");
$sel
(my $fh, '>', $file)
or die "failed to open $type file $file\n";
print {$fh} encode_json($self->{data});
close $fh;
$self->{logger}->("saved $type file $file");
}
sub purge {
nt;
use strict;
use v5.10;
our $VERSION = '0.30';
use HTTP::Tiny 0.024;
use URI;
use App::PAIA::JSON;
sub new {
my ($class, %options) = @_;
bless {
insecure => !!$options{insecure},
) // '';
my $param = shift // {};
my $headers = {
Accept => 'application/json',
'User-Agent' => "App::PAIA/".($APP::PAIA::VERSION//'?'),
@_
};
my $con
}
if ($method eq 'POST') {
$headers->{'Content-Type'} = 'application/json';
$content = encode_json($param);
} elsif (%$param) {
$url->query_form(%$param);
}
$
5.10;
our $VERSION = '0.30';
use App::Cmd::Setup -command;
use App::PAIA::Agent;
use App::PAIA::JSON;
use App::PAIA::File;
use URI::Escape;
use URI;
# TODO: move option handling to App::PAIA
# Imp
my ($response, $json) = $self->agent->request( $method, $url, $param, %headers );
# handle request errors
if (ref $json and defined $json->{error}) {
my $msg = $json->{error};
if (defined $json->{error_description}) {
$msg .= ': '.$json->{error_description};
}
die "$msg\n";
}
if ($response->{status} ne '200') {
my $msg = $respo
ode
stdout_json stderr_json output_json error exit_code
));
use Test::More;
use App::Cmd::Tester;
use File::Temp qw(tempdir);
use Cwd;
use App::PAIA;
use JSON::PP qw(encode_json);
use Scalar:
;
sub decode_json {
my $json = shift;
$json =~ s/^#.*$//mg;
JSON::PP::decode_json($json)
}
sub stdout_json() { decode_json($RESULT->stdout) }
sub stderr_json() { decode_json($RESULT->std
err) }
sub output_json() { decode_json($RESULT->output) }
## no critic
eval "sub $_() { \$RESULT->$_ }" for qw(stdout stderr output error exit_code);
our $HTTP_TINY_REQUEST = \&HTTP::Tiny::request;
;
use strict;
use v5.10;
use parent 'App::PAIA::Command';
our $VERSION = '0.30';
use App::PAIA::JSON;
sub usage_desc {
"%c config %o [ key [value] ]"
}
sub opt_spec {
['ini|i' => 'list con
- show or modify configuration
=head1 DESCRIPTION
This command shows or modifies the current configuration. Configuration
is printed as JSON object or in INI-sytle as sorted key-value-pairs.
=cut
';
use App::PAIA::JSON;
sub _execute {
my ($self, $opt, $args) = @_;
if (defined $self->session->file ) {
my $data = $self->session->load;
say encode_json($data) if $self->a
;
use strict;
use v5.10;
use parent 'App::PAIA::Command';
our $VERSION = '0.30';
use App::PAIA::JSON;
sub _execute {
my ($self, $opt, $args) = @_;
if ($self->expired) {
$self->logg
"POST", "$auth/logout", { patron => $self->patron }
);
print encode_json($response);
}
$self->session->purge && $self->logger->("deleted session file");
ret
],
['config|c=s' => "configuration file (default: ./paia.json)"],
['session|s=s' => "session file (default: ./paia-session.json)"],
['verbose|v' => "show what's going on internally"]