view release on metacpan or search on metacpan
lib/Catmandu/Store/AAT/SPARQL.pm view on Meta::CPAN
my $form = {
'query' => $self->query
};
my $response = $self->ua->post($self->url, $form);
if ($response->is_success) {
return decode_json($response->decoded_content);
} else {
Catmandu::HTTPError->throw({
code => $response->code,
message => $response->status_line,
url => $response->request->uri,
method => $response->request->method,
request_headers => [],
request_body => $response->request->decoded_content,
response_headers => [],
response_body => $response->decoded_content
});
return undef;
}
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Catmandu/Store/Datahub/API.pm view on Meta::CPAN
my $url = sprintf('%s/api/v1/data/%s', $self->url, $id);
my $response = $self->client->get($url, Authorization => sprintf('Bearer %s', $self->access_token));
if ($response->is_success) {
return decode_json($response->decoded_content);
} elsif ($response->code == 401) {
my $error = decode_json($response->decoded_content);
if ($error->{'error_description'} eq 'The access token provided has expired.') {
$self->set_access_token();
return $self->get($id);
}
} elsif ($response->code == 404) {
return {};
} else {
my $message = decode_json($response->decoded_content);
Catmandu::HTTPError->throw({
code => $response->code,
message => $message->{error}->{msg},
url => $response->request->uri->as_string,
method => $response->request->method,
request_headers => [],
request_body => $response->request->decoded_content,
response_headers => [],
response_body => $response->decoded_content,
});
return undef;
}
}
lib/Catmandu/Store/Datahub/API.pm view on Meta::CPAN
my $response;
$response = $self->client->post($url, Content_Type => 'application/lido+xml', Authorization => sprintf('Bearer %s', $token), Content => $data);
if ($response->is_success) {
return $response->decoded_content;
} elsif ($response->code == 401) {
my $error = decode_json($response->decoded_content);
if ($error->{'error_description'} eq 'The access token provided has expired.') {
$self->set_access_token();
return $self->add($data);
}
} else {
my $message = decode_json($response->decoded_content);
Catmandu::HTTPError->throw({
code => $response->code,
message => $message->{error}->{msg},
url => $response->request->uri->as_string,
method => $response->request->method,
request_headers => [],
request_body => $response->request->decoded_content,
response_headers => [],
response_body => $response->decoded_content,
});
return undef;
}
}
lib/Catmandu/Store/Datahub/API.pm view on Meta::CPAN
my $response;
$response = $self->client->put($url, Content_Type => 'application/lido+xml', Authorization => sprintf('Bearer %s', $token), Content => $data);
if ($response->is_success) {
return $response->decoded_content;
} elsif ($response->code == 401) {
my $error = decode_json($response->decoded_content);
if ($error->{'error_description'} eq 'The access token provided has expired.') {
$self->set_access_token();
return $self->update($id, $data);
}
} else {
my $message = decode_json($response->decoded_content);
Catmandu::HTTPError->throw({
code => $response->code,
message => $message->{error}->{msg},
url => $response->request->uri->as_string,
method => $response->request->method,
request_headers => [],
request_body => $response->request->decoded_content,
response_headers => [],
response_body => $response->decoded_content,
});
return undef;
}
}
lib/Catmandu/Store/Datahub/API.pm view on Meta::CPAN
my $response;
$response = $self->client->delete($url, Authorization => sprintf('Bearer %s', $token));
if ($response->is_success) {
return $response->decoded_content;
} elsif ($response->code == 401) {
my $error = decode_json($response->decoded_content);
if ($error->{'error_description'} eq 'The access token provided has expired.') {
$self->set_access_token();
return $self->delete($id);
}
} else {
my $message = decode_json($response->decoded_content);
Catmandu::HTTPError->throw({
code => $response->code,
message => $message->{error}->{msg},
url => $response->request->uri->as_string,
method => $response->request->method,
request_headers => [],
request_body => $response->request->decoded_content,
response_headers => [],
response_body => $response->decoded_content,
});
return undef;
}
}
lib/Catmandu/Store/Datahub/API.pm view on Meta::CPAN
my $token = $self->access_token;
my $response = $self->client->get($url, Authorization => sprintf('Bearer %s', $token));
if ($response->is_success) {
return decode_json($response->decoded_content);
} else {
my $message = decode_json($response->decoded_content);
Catmandu::HTTPError->throw({
code => $response->code,
message => $message->{error}->{msg},
url => $response->request->uri->as_string,
method => $response->request->method,
request_headers => [],
request_body => $response->request->decoded_content,
response_headers => [],
response_body => $response->decoded_content,
});
return undef;
}
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Catmandu/Store/REST/API.pm view on Meta::CPAN
my $url = $self->mk_url($id);
my $response = $self->client->get($url);
if ($response->is_success) {
return decode_json($response->decoded_content);
} elsif ($response->code == 404) {
return {};
} else {
Catmandu::HTTPError->throw({
code => $response->code,
message => $response->status_line,
url => $response->request->url,
method => $response->request->method,
request_headers => [],
request_body => $response->request->decoded_content,
response_headers => [],
response_body => $response->decoded_content,
});
return {};
}
}
lib/Catmandu/Store/REST/API.pm view on Meta::CPAN
my $json_data = encode_json($data);
my $response = $self->client->post($url, Content_Type => 'application/json', Content => $json_data);
if ($response->is_success) {
return decode_json($response->decoded_content);
} else {
Catmandu::HTTPError->throw({
code => $response->code,
message => $response->status_line,
url => $response->request->url,
method => $response->request->method,
request_headers => [],
request_body => $response->request->decoded_content,
response_headers => [],
response_body => $response->decoded_content,
});
return {};
}
}
lib/Catmandu/Store/REST/API.pm view on Meta::CPAN
my $json_data = encode_json($data);
my $response = $self->client->put($url, Content_Type => 'application/json', Content => $json_data);
if ($response->is_success) {
return decode_json($response->decoded_content);
} else {
Catmandu::HTTPError->throw({
code => $response->code,
message => $response->status_line,
url => $response->request->url,
method => $response->request->method,
request_headers => [],
request_body => $response->request->decoded_content,
response_headers => [],
response_body => $response->decoded_content,
});
return {};
}
}
lib/Catmandu/Store/REST/API.pm view on Meta::CPAN
my $url = $self->mk_url($id);
my $response = $self->client->delete($url);
if ($response->is_success) {
return decode_json($response->decoded_content);
} else {
Catmandu::HTTPError->throw({
code => $response->code,
message => $response->status_line,
url => $response->request->url,
method => $response->request->method,
request_headers => [],
request_body => $response->request->decoded_content,
response_headers => [],
response_body => $response->decoded_content,
});
return {};
}
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Catmandu/Store/RKD/API/Search.pm view on Meta::CPAN
} else {
$url = $self->url;
}
my $response = $self->engine->get($url);
if ($response->is_success) {
return $response->decoded_content;
} else {
Catmandu::HTTPError->throw({
code => $response->code,
message => $response->status_line,
url => $response->request->uri,
method => $response->request->method,
request_headers => [],
request_body => $response->request->decoded_content,
response_headers => [],
response_body => $response->decoded_content,
});
return undef;
}
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Catmandu/VIAF/API/ID.pm view on Meta::CPAN
code => $response->code,
message => $response->status_line,
url => $response->request->uri,
method => $response->request->method,
request_headers => [],
request_body => $response->request->decoded_content,
response_headers => [],
response_body => $response->decoded_content
});
return {};
}
}
my $rdf = $response->decoded_content;
my $document = sprintf('<?xml version="1.0" encoding="UTF-8"?>%s', $rdf);
my $parser = Catmandu::VIAF::API::Parse->new(items => $document);
return $parser->xml();
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Chandra/Socket/Connection.pm view on Meta::CPAN
=head2 recv
my @messages = $conn->recv;
Non-blocking read. Returns decoded message hashes, or an empty list if
no complete frames are available. Sets C<is_connected> to false on EOF
or error.
=head2 is_connected
view all matches for this distribution
view release on metacpan or search on metacpan
examples/bitcoin.pl view on Meta::CPAN
$ua->agent('Mozilla/5.0'); # LWP UserAgent banned by default... Don't shoot the messenger...
$ua->default_header( 'Content-Type' => 'application/json' );
my $response = $ua->get('https://api.pro.coinbase.com/products/BTC-EUR/candles');
if ( $response->is_success() ) {
my $data = from_json( $response->decoded_content );
my ( @x, @open, @close, @high, @low );
for my $candle (@$data) {
push @x, DateTime->from_epoch( epoch => $candle->[0] );
push @low, $candle->[1];
push @high, $candle->[2];
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Chat/iFly.pm view on Meta::CPAN
sub _process_response {
my $self = shift;
my $response = shift;
if ($response->is_success) {
return $response->decoded_content;
}
else {
warn $response->decoded_content;
ouch $response->code, $response->message, $response->decoded_content;
}
}
=head1 PREREQS
view all matches for this distribution
view release on metacpan or search on metacpan
CheerLights/API.pm view on Meta::CPAN
my ($url) = @_;
my $ua = LWP::UserAgent->new;
my $response = $ua->get($url);
if ($response->is_success) {
return $response->decoded_content;
} else {
warn "Failed to fetch URL: " . $response->status_line;
return;
}
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Chef/Encoder.pm view on Meta::CPAN
returns base64 encoded value of data
=head4 B<decode>
it accepts data as parameter $obj->decode( 'data' => $data )
returns base64 decoded value of data
=cut
#-------------------------------#
# class Chef::Encoder::base64 #
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Chess/PGN/Extract.pm view on Meta::CPAN
$out =~ s/\n//g;
$out =~ s/}/},/g;
chop $out;
$out = "[" . $out . "]";
my $decoded = try {
decode_json ($out);
} catch {
croak ("JSON parse error: $out");
};
lib/Chess/PGN/Extract.pm view on Meta::CPAN
else {
my $invalid_game = dump ($_);
STDERR->print ("Invalid PGN omitted: $invalid_game\n");
0;
}
} @$decoded;
foreach (@games) {
delete $_->{chash};
delete $_->{fhash};
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Chess/Plisco.pod view on Meta::CPAN
Generates a string representation of all bitboards in ASCII art plus some
additional information.
=item B<dumpInfo(INFO)>
Returns a string with the decoded position information as retured by
L</info>.
=item B<movesCoordinateNotation(MOVES)>
Takes an array of moves (as integers) and converts it into an array of moves
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Chouette.pm view on Meta::CPAN
L<Chouette> is a framework for making asynchronous HTTP services. It makes some opinionated design choices, but is otherwise fairly flexible.
L<AnyEvent> is used as the glue to connect all the asynchronous libraries, although Chouette depends on L<Feersum> and therefore L<EV> for its event loop. It uses L<Feersum> in PSGI mode so it can use L<Plack> for request parsing, and has support for...
Chouette generally assumes that its input will be C<application/x-www-form-urlencoded>. L<Plack::Request::WithEncoding> is used so that text is properly decoded (we recommend UTF-8 of course). For output, the default is C<application/json> encoded wi...
Chouette apps can optionally load a config file and its format is C<YAML>, loaded with the L<YAML> module. L<Regexp::Assemble> is used for efficient route-dispatch.
The above aside, Chouette's main purpose is to glue together several of my own modules into a cohesive whole. These modules have been designed to work together and I have used them to build numerous services, some of which handle a considerable amoun...
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Circle/Common.pm view on Meta::CPAN
$header = [ 'Content-Type' => 'application/json; charset=UTF-8' ];
}
my $request = HTTP::Request->new( 'POST', $url, $header, encode_json($data) );
my $response = $ua->request($request);
if ( $response->is_success ) {
return decode_json( $response->decoded_content );
}
else {
carp 'http_json_post' . $response->status_line ? $response->status_line : 'unknown';
return {
status => $response->status_line,
message => $response->decoded_content,
};
}
}
sub http_json_get {
lib/Circle/Common.pm view on Meta::CPAN
$header = [ 'Content-Type' => 'application/json; charset=UTF-8' ];
}
my $request = HTTP::Request->new( 'GET', $url, $header );
my $response = $ua->request($request);
if ( $response->is_success ) {
return decode_json( $response->decoded_content );
}
else {
carp 'http_json_get' . $response->status_line ? $response->status_line : 'unknown';
return {
status => $response->status_line,
message => $response->decoded_content,
};
}
}
sub get_host {
view all matches for this distribution
view release on metacpan or search on metacpan
lib/ClarID/Tools/Command/qrcode.pm view on Meta::CPAN
option 'outfile' => (
is => 'ro',
format => 's',
isa => Str,
default => sub { 'decoded.csv' },
doc => 'Where to write CSV (decode directory mode only)',
);
option 'sep' => (
is => 'ro',
lib/ClarID/Tools/Command/qrcode.pm view on Meta::CPAN
or croak "ERROR: 'zbarimg' not found in PATH";
# Single-file decode mode
if (-f $self->input && $self->input =~ /\.png$/i) {
my $file = $self->input;
chomp(my $decoded = qx(zbarimg --raw "$file" 2>/dev/null));
die "ERROR: no QR code found in '$file'\n" unless length $decoded;
say $decoded;
return 1;
}
# Directory decode mode
my $col_name = $self->column || 'clar_id';
lib/ClarID/Tools/Command/qrcode.pm view on Meta::CPAN
or croak "ERROR: Cannot write to '$self->outfile': $!";
print $out "$col_name\n";
for my $f (@files) {
my $path = "$self->{input}/$f";
chomp(my $decoded = qx(zbarimg --raw "$path" 2>/dev/null));
next unless length $decoded;
$decoded =~ s/\r?\n//g;
print $out "$decoded\n";
}
close $out;
say "Decoded CSV written to '$self->{outfile}'";
}
view all matches for this distribution
view release on metacpan or search on metacpan
t/06-encoding.t view on Meta::CPAN
};
isa_ok my $p1 = Class::Param->new($params), 'Class::Param', 'Class::Param->new constructs a new instance';
isa_ok my $p2 = Class::Param::Encoding->new($p1), 'Class::Param::Encoding', 'Class::Param::Encoding->new constructs a new instance';
is $p2->get('A'), "\x{263A}", '->get A: returns right decoded value';
is $p2->param('A'), "\x{263A}", '->param A: returns right decoded value';
is $p2->get('B'), "\x{2639}", '->get B: returns right decoded value';
is $p2->param('B'), "\x{2639}", '->param B: returns right decoded value';
is_deeply $p2->get('C'), [ "\x{263A}", "\x{2639}" ], '->get C: returns right decoded values';
is_deeply [ $p2->param('C') ], [ "\x{263A}", "\x{2639}" ], '->param C: returns right decoded values';
is $p2->get('D'), "\x{263A}", '->get D: returns right decoded value';
is $p2->param('D'), "\x{263A}", '->param D: returns right decoded value';
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Class/Usul/Functions.pm view on Meta::CPAN
Untaints directory path. Makes it an absolute path and returns it if it
exists. Returns undef otherwise
=head2 C<base64_decode_ns>
$decoded_value = base64_decode_ns $encoded_value;
Decode a scalar value encode using L</base64_encode_ns>
=head2 C<base64_encode_ns>
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Claude/Agent/MCP/SDKRunner.pm view on Meta::CPAN
# Limit tools_json size to prevent memory exhaustion (1MB limit)
die "tools_json too large (max 1MB)\n" if length($tools_json) > 1_000_000;
my ($tools) = $state->{jsonl}->decode($tools_json);
# Validate decoded structure: must be an array of tool definitions
die "Invalid tools_json: expected array\n" unless ref $tools eq 'ARRAY';
for my $tool (@$tools) {
die "Invalid tool definition: expected hash with 'name' key\n"
unless ref $tool eq 'HASH' && defined $tool->{name};
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/ClearPress/authenticator/session.pm view on Meta::CPAN
}
sub decode_token {
my ($self, $token) = @_;
my $decoded = q[];
eval {
$decoded = decode_base64($token);
} or do {
carp q[Failed to decode token];
return;
};
my $decrypted = q[];
eval {
$decrypted = $self->cipher->decrypt($decoded);
} or do {
carp q[Failed to decrypt token];
return;
};
view all matches for this distribution
view release on metacpan or search on metacpan
eg/json_query.pl view on Meta::CPAN
#!/usr/bin/env perl
# json_query.pl - run a select against a JSON column, decode rows via
# decode_blocks, walk the decoded objects in Perl.
#
# Usage:
# json_query.pl --table events --where "j.user.id = 42"
#
# Demonstrates:
# - HTTP select format native returns a concatenated stream of blocks;
# decode_blocks() walks them
# - The decoded JSON values are nested Perl hashrefs (dotted paths
# auto-unflattened on the way back)
use strict;
use warnings;
use Getopt::Long;
use HTTP::Tiny;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/CloudFlare/Client.pm view on Meta::CPAN
CloudFlare::Client::Exception::Connection::->throw(
status => $res->status_line,
message => 'HTTPS request failed',)
unless $res->is_success;
# Handle errors from CF
Readonly my $info => decode_json($res->decoded_content);
CloudFlare::Client::Exception::Upstream::->throw(
errorCode => $info->{err_code},
message => $info->{msg},)
unless $info->{result} eq 'success';
view all matches for this distribution
view release on metacpan or search on metacpan
1.19 2016-03-28 12:13:34 -0400
- make hypnotoad test a dev only test
1.18 2016-03-24 15:49:47 -0400
- Documentation fixes
- Fix bug where errors from mojo were not being decoded correctly
in PlugAuth plugin
- make plackup test a dev only test
1.17 2016-03-14 12:18:27 -0400
- removed stragler deprecated use of auth_ua
view all matches for this distribution
view release on metacpan or search on metacpan
examples/helloworld/app/lib/Dwarf/Module/SocialMedia/Amazon.pm view on Meta::CPAN
if ($res->code !~ /^2/) {
$self->on_error->('Amazon OAuth Error: Could not get access token.');
return;
}
my $decoded = decode_json $res->{_content};
my $access_token = $decoded->{access_token};
$self->access_token($access_token);
}
sub _make_request {
examples/helloworld/app/lib/Dwarf/Module/SocialMedia/Amazon.pm view on Meta::CPAN
return $self->validate($res);
}
sub validate {
my ($self, $res) = @_;
my $content = eval { decode_json($res->decoded_content) };
if ($@) {
warn "Couldn't decode JSON: $@";
$content = $res->decoded_content;
}
# [todo]
# check error status codes
view all matches for this distribution
view release on metacpan or search on metacpan
lib/CodeGen/Cpppp/CParser.pm view on Meta::CPAN
[ $type, $value, $offset, $length, $error=undef ]
$type: 'directive', 'comment', 'string', 'char', 'real', 'integer',
'keyword', 'ident', 'unknown', or any punctuation character
$value: for constants, this is the decoded string or numeric value
for directives and comments, it is the body text
for punctuation, it is a copy of $type
for unknown, it is the exact character that didn't parse
$src_pos: the character offset within the source $string
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Codec/CBOR.pm view on Meta::CPAN
return $buf;
}
if ( $major == 3 ) { # UTF-8 string
my $len = $self->_decode_value( $info, $fh );
read( $fh, my $buf, $len );
my $decoded = $buf;
return $decoded if utf8::decode($decoded);
# Fallback for invalid UTF-8: return raw bytes
return $buf;
}
if ( $major == 4 ) { # Array
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Coerce/Types/Standard.pm view on Meta::CPAN
=back
=head2 HTML
Accepts a String and coerces it into entity encoded/decoded string, the default behaviour here is to entity encode the given string.
HTML->coerce('okay&');
*-*-*-*-*-*-*
okay&
view all matches for this distribution
view release on metacpan or search on metacpan
lib/CohortExplorer/Application/Opal/Datasource.pm view on Meta::CPAN
Accept => "application/json"
);
my $res = $ua->request($req);
my $code = $res->code;
if ( $code == 200 ) {
my $json = decode_json( $res->decoded_content );
if ( $json->{type} ne 'mongodb' ) {
# Successful authentication returns tables and views accessible to the user
my %view = map { $_ => 1 } @{ $json->{view} || [] };
my @tables = @{ $json->{table} || [] };
lib/CohortExplorer/Application/Opal/Datasource.pm view on Meta::CPAN
);
my $entity_res = $ua->request($entity_req);
# Get the first identifier
if ( $entity_res->code == 200 ) {
my $decoded_json = decode_json( $entity_res->decoded_content );
my $var_req =
HTTP::Request->new( GET => $url
. "/ws/datasource/$ds_name/table/$t/valueSet/"
. ( $decoded_json->[0]->{identifier} || '' ) );
$var_req->header(
Authorization => "X-Opal-Auth "
. MIME::Base64::encode( join ':', @opts{qw/username password/} ),
Accept => "application/json"
);
my $var_res = $ua->request($var_req);
# Get all variables with accessible values
if ( $var_res->code == 200 ) {
$decoded_json = decode_json( $var_res->decoded_content );
push @{ $param{allowed_variables} },
map { "$t.$_" } @{ $decoded_json->{variables} };
}
else {
die "Failed to fetch variable list via $url (error "
. $var_res->code . ")\n";
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Command/Run/Tmpfile.pm view on Meta::CPAN
Create a new temporary file object.
By default the underlying file handle is opened with the
C<:encoding(utf8)> layer, so character strings are encoded to UTF-8 on
write and decoded on read.
When C<raw> is true, the C<:raw> layer is used instead, making the file
a transparent byte container: whatever bytes are written are stored and
read back unchanged. Use this when you write data that is already a
byte stream (for example the output of an external command captured with
view all matches for this distribution
view release on metacpan or search on metacpan
t/03_render.t view on Meta::CPAN
is(CommonMark->markdown_to_html("\x{263A}"), "<p>\x{263A}</p>\n",
'render functions return encoded utf8');
is(CommonMark->markdown_to_html("\xC2\xA9"), "<p>\xC2\xA9</p>\n",
'render functions expect decoded utf8');
view all matches for this distribution
view release on metacpan or search on metacpan
t/app/Plack/Request.t view on Meta::CPAN
Returns the protocol (HTTP/1.0 or HTTP/1.1) used for the current request.
=item request_uri
Returns the raw, undecoded request URI path. You probably do B<NOT>
want to use this to dispatch requests.
=item path_info
Returns B<PATH_INFO> in the environment. Use this to get the local
t/app/Plack/Request.t view on Meta::CPAN
$req->logger->({ level => 'debug', message => "This is a debug message" });
=item cookies
Returns a reference to a hash containing the cookies. Values are
strings that are sent by clients and are URI decoded.
If there are multiple cookies with the same name in the request, this
method will ignore the duplicates and return only the first value. If
that causes issues for you, you may have to use modules like
CGI::Simple::Cookie to parse C<$request->header('Cookies')> by
t/app/Plack/Request.t view on Meta::CPAN
Returns a L<Hash::MultiValue> hash reference containing (merged) GET
and POST parameters.
=item content, raw_body
Returns the request content in an undecoded byte string for POST requests.
=item uri
Returns an URI object for the current request. The URI is constructed
using various environment values such as C<SCRIPT_NAME>, C<PATH_INFO>,
view all matches for this distribution