view release on metacpan or search on metacpan
devel/Casablanca.pm view on Meta::CPAN
foreach my $symbol (@symbol_list) {
my $url = make_url ($symbol);
my $req = HTTP::Request->new ('GET', $url);
$ua->prepare_request ($req);
$req->accept_decodable; # we know decoded_content() below
$req->user_agent (__PACKAGE__."/$VERSION " . $req->user_agent);
### Request: $req->as_string
my $resp = $ua->request ($req);
resp_to_quotes ($fq, $symbol, $resp, \%quotes);
devel/Casablanca.pm view on Meta::CPAN
$quotes->{$symbol,'currency'} = 'MAD';
$quotes->{$symbol,'source'} = __PACKAGE__;
$quotes->{$symbol,'success'} = 1;
# defaults to latin1, which is right
my $content = $resp->decoded_content (raise_error => 1, charset => 'none');
if (! $resp->is_success) {
$quotes->{$symbol,'success'} = 0;
$quotes->{$symbol,'errormsg'} = $resp->status_line;
return;
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Finance/Quote/IEX.pm view on Meta::CPAN
$info{ $symbol, 'errormsg' }
= sprintf( $errormsg, $symbol, $url, $code, $desc );
next;
}
my $data = decode_json( $response->decoded_content );
if ( !defined $data->{latestPrice} ) {
my $code = $response->code;
my $desc = status_message($code);
$info{ $symbol, 'success' } = 0;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Finance/Quote/ASX.pm view on Meta::CPAN
$error = "Failed to parse JSON data from ASX server '$url'. Error: '$@'.";
### ASX.pm Error: $error
return $status, $error, undef;
}
# Return valid, decoded data
$status = 1;
return $status, $error, $data;
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Finnigan.pm view on Meta::CPAN
my $o = Finnigan::Object->decode(\*STREAM, $arg);
$o->dump;
where 'Object' is a symbol for any of the specific decoder objects
(C<Finnigan::*>) and C<STREAM> is an open filehandle positioned at the
start of the structure to be decoded. Some decoders may require an
additional argument (file format version).
=head1 DESCRIPTION
C<Finnigan> is a non-functional package whose only purpose is to pull
lib/Finnigan.pm view on Meta::CPAN
=item decode($stream, $arg)
Each C<Finnigan::*> object has a constructor method named C<decode()>,
whose first argument is a filehandle positioned at the start of the
object to be decoded. Some decoders require additional arguments, such
as the file version number. A single argument is passed as it is,
while multiple arguments can be passed as an array reference.
The constructor advances the handle to the start of the next object,
so seeking to the start of the object of interest is only necessary
lib/Finnigan.pm view on Meta::CPAN
calling of object constructors in sequency. In reality, it is often
more efficient to seek ahead to fetch an index structure stored near
the end of the file, then go back to the data stream using the
pointers in the index.
The decoded data can be obtained by calling accessor methods on the
object or by de-referencing the object reference (since all Finnigan
objects are blessed hash references):
$x = $object->element
lib/Finnigan.pm view on Meta::CPAN
=item dump(%args)
All Finnigan objects are the descendants of L<Finnigan::Decoder>. One
of the methods they inherit is C<dump>, which provides an easy way to
explore the contents of decoded objects. The C<dump> method prints out
the structure of the object it is called on in a few styles, with
relative or absolute addressess.
For example, many object dumps used in L<this
wiki|http://code.google.com/p/unfinnigan/wiki/WikiHome> were created
lib/Finnigan.pm view on Meta::CPAN
inspecting the structures with the C<dump> method.
This may seem like a kludgy way of reading four bytes, but the upshot
is that the resulting C<$object> will have the size, type and location
information tucked into it, so it can be analysed and dumped in a way
consistent with other decoded objects. The advantage becomes even more
apparent when the structure is more complex than a single scalar object.
The inherited C<read> method provides the core functionality in all Finnigan
decoders.
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Firebase.pm view on Meta::CPAN
sub process_response {
my ($self, $response) = @_;
$self->debug($response->header('X-Firebase-Auth-Debug'));
if ($response->is_success) {
if ($response->decoded_content eq 'null') {
return undef;
}
else {
my $result = eval { from_json($response->decoded_content) };
if ($@) {
warn $response->decoded_content;
ouch 500, 'Server returned unparsable content.';#, { error => $@, content => $response->decoded_content };
}
return $result;
}
}
else {
ouch 500, $response->status_line, $response->decoded_content;
}
}
=head1 NAME
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Flickr/API.pm view on Meta::CPAN
if ($response->{_rc} != 200){
$response->set_fail(0, "API returned a non-200 status code ($response->{_rc})");
return $response;
}
my $content = $response->decoded_content();
$content = $response->content() unless defined $content;
my $xls = XML::LibXML::Simple->new(ForceArray => 0);
my $tree = XML::Parser::Lite::Tree::instance()->parse($content);
lib/Flickr/API.pm view on Meta::CPAN
if ($response->{_rc} != 200){
$response->set_fail(0, "Upload returned a non-200 status code ($response->{_rc})");
return $response;
}
my $content = $response->decoded_content();
$content = $response->content() unless defined $content;
my $xls = XML::LibXML::Simple->new(ForceArray => 0);
my $tree = XML::Parser::Lite::Tree::instance()->parse($content);
lib/Flickr/API.pm view on Meta::CPAN
$orequest->sign;
my $response = $self->get($orequest->to_url);
my $content = $response->decoded_content();
$content = $response->content() unless defined $content;
if ($content =~ m/^oauth_problem=(.+)$/) {
carp "\nRequest token not granted: '",$1,"'\n";
lib/Flickr/API.pm view on Meta::CPAN
$request->sign;
my $response = $self->get($request->to_url);
my $content = $response->decoded_content();
$content = $response->content() unless defined $content;
if ($content =~ m/^oauth_problem=(.+)$/) {
carp "\nAccess token not granted: '",$1,"'\n";
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Flickr/API2/Raw.pm view on Meta::CPAN
my $response = $self->do_request($request);
croak("API call failed with HTTP status: " . $response->code)
unless $response->code == 200;
my $content = $response->decoded_content;
$content = $response->content() unless defined $content;
my $json = eval { decode_json($content) };
if ($@) {
croak("Failed to parse API response as JSON. Error=$@\nContent=$content\n");
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Flickr/Upload/Dopplr.pm view on Meta::CPAN
eval {
my $fl = Flickr::API->new({'key' => $self->{'api_key'}});
my $res = $fl->execute_method('flickr.places.find', {'query' => $query});
my $fl_xml = $res->decoded_content();
my $fl_xp = XML::XPath->new('xml' => $fl_xml);
# Wait to see if any more actual magic is required...
my @places = $fl_xp->findnodes("/rsp/places/place");
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Flickr/Upload/FireEagle.pm view on Meta::CPAN
# please cache me...
my ($lat, $lon) = $self->gps_exif_to_latlon($info);
try {
my $res = $self->flickr_api_call('flickr.places.findByLatLon', {'lat' => $lat, 'lon' => $lon});
my $xml = XML::XPath->new('xml' => $res->decoded_content());
my $fe_placeid = $ctx->findvalue("place-id");
my $fl_placeid = $xml->findvalue("/rsp/places/place/\@place_id")->string_value();;
if ($fe_placeid ne $fl_placeid){
lib/Flickr/Upload/FireEagle.pm view on Meta::CPAN
my $self = shift;
my $placeid = shift;
try {
my $res = $self->flickr_api_call('flickr.places.resolvePlaceId', {'place_id' => $placeid});
my $xml = XML::XPath->new('xml' => $res->decoded_content());
return $xml->findvalue("/rsp/location/\@name");
}
catch Error with {
lib/Flickr/Upload/FireEagle.pm view on Meta::CPAN
return lc($tag);
}
#
# Just so so so wrong...but necessary until Flickr::Upload
# is updated to call $res->decoded_content()
#
sub upload_request($$) {
my $self = shift;
die "$self is not a LWP::UserAgent" unless $self->isa('LWP::UserAgent');
my $req = shift;
die "expecting a HTTP::Request" unless $req->isa('HTTP::Request');
my $res = $self->request( $req );
my $tree = XML::Parser::Lite::Tree::instance()->parse($res->decoded_content());
return () unless defined $tree;
my $photoid = response_tag($tree, 'rsp', 'photoid');
my $ticketid = response_tag($tree, 'rsp', 'ticketid');
unless( defined $photoid or defined $ticketid ) {
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Flickr/Upload.pm view on Meta::CPAN
# Try to upload
$res = $self->request( $req );
return () unless defined $res;
if ($res->is_success) {
$xml = XMLin($res->decoded_content, KeyAttr=>[], ForceArray=>0);
return () unless defined $xml;
last;
} else {
my $what_next = ($try == $tries ? "giving up" : "trying again");
my $status = $res->status_line;
lib/Flickr/Upload.pm view on Meta::CPAN
}
my $photoid = $xml->{photoid};
my $ticketid = $xml->{ticketid};
unless( defined $photoid or defined $ticketid ) {
print STDERR "upload failed:\n", $res->decoded_content(), "\n";
return undef;
}
return (defined $photoid) ? $photoid : $ticketid;
}
lib/Flickr/Upload.pm view on Meta::CPAN
'auth_token' => $auth_token,
} ) ;
#TODO: Add detailed error messages
return undef unless defined $res and $res->{success};
my $hash = XMLin($res->decoded_content(), KeyAttr=>[], ForceArray=>0);
my $photoset_id = $hash->{photoset}->{id};
if ( ! defined $photoset_id ) {
warn "Failed to extract photoset ID from response:\n" .
$res->decoded_content() . "\n\n";
return undef;
}
return $photoset_id ;
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Flux/Format.pm view on Meta::CPAN
=head1 SYNOPSIS
$json_storage = $json_format->wrap($storage);
$json_storage->write({ a => "b" });
$in = $json_storage->in("client1");
$data = $in->read(); # data is decoded again
=head1 DESCRIPTION
There's a common need to store complex data into storages which can only store strings.
lib/Flux/Format.pm view on Meta::CPAN
=item B<< wrap($storage) >>
Construct a formatted storage. Returns a new storage object.
Resulting object will transform all writes using C<encoder> and generate input streams which are pre-decoded by C<decoder>.
Unlike C<encoder> and C<decoder>, this method is provided by this role.
=back
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Footprintless/Plugin/Atlassian/Confluence/ResponseParser.pm view on Meta::CPAN
my %response = (
code => $http_response->code(),
message => $http_response->message(),
);
my $content = $http_response->decoded_content();
if ( $http_response->is_success() ) {
$response{success} = 1;
$response{content} = $content ? decode_json($content) : '';
}
else {
$response{success} = 0;
$response{content} = $http_response->decoded_content();
}
return \%response;
}
lib/Footprintless/Plugin/Atlassian/Confluence/ResponseParser.pm view on Meta::CPAN
my $response = {
status => 0, # truthy if $http_response->is_success()
code => 200, # $http_response->code()
message => 'Success', # $http_response->message()
content => {} # decode_json($http_response->decoded_content())
};
=head1 CONSTRUCTORS
=head2 new()
view all matches for this distribution
view release on metacpan or search on metacpan
$self->{ 'LWP_OBJ' }->timeout( $self->{'TIMEOUT'} ); }
$response = $self->{'LWP_OBJ'}->get( $self->{ 'REQUEST_URL' } );
if ( $response->is_success )
{ $self->{ 'CONTENT' } = decode_json $response->decoded_content; $LASTERROR = undef; }
else
{ $self->{ 'ERROR'} = decode_json $response->decoded_content;
$LASTERROR = 1; }
delete $self->{ 'REQUEST_URL' };
1;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Forks/Super/LazyEval/BackgroundArray.pm view on Meta::CPAN
"operate on 'tainted' data. Use bg_eval {...} ",
'{untaint => 1} or bg_qx COMMAND, ',
"{untaint => 1} to retrieve the result.\n";
return;
}
my $decoded = eval "$data"; ## no critic (StringyEval)
return $decoded;
}
},
);
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Frontier/RPC2.pm view on Meta::CPAN
=item encoding
The XML encoding to be specified in the XML declaration of encoded RPC
requests or responses. Decoded results may have a different encoding
specified; XML::Parser will convert decoded data to UTF-8. The
default encoding is none, which uses XML 1.0's default of UTF-8. For
example:
$server = Frontier::RPC2->new( 'encoding' => 'ISO-8859-1' );
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Froody/API/XML.pm view on Meta::CPAN
<photo photo_id="1123" />
<photo photo_id="2345" />
</photos>
Currently we accept both a well-formed XML fragment and an
entity-encoded string that can be decoded to an XML fragment.
=item <errors>
A list of errors of this form:
view all matches for this distribution
view release on metacpan or search on metacpan
old_test.pl view on Meta::CPAN
# OAUTH REQUIRES HANDLING OF THESE PARAMETERS (SIG GENERATION)
# - query component of URI
# - The OAuth HTTP "Authorization" header field (Section 3.5.1) if
# present. The header's content is parsed into a list of name/value
# pairs excluding the "realm" parameter if present. The parameter
# values are decoded as defined by Section 3.5.1.
# - the request body IF
# 1. body is single part
# 2. body is application/x-www-form-urlencoded
# 3. body Content-Type is application/x-www-form-urlencoded
# - EXCLUDE "oauth_signature" parameter from sig generation IF PRESENT
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Furl/Response.pm view on Meta::CPAN
sub content_encoding { shift->headers->content_encoding() }
sub header { shift->headers->header(@_) }
sub protocol { "HTTP/1." . $_[0]->{minor_version} }
sub decoded_content {
my $self = shift;
my $cloned = $self->headers->clone;
# 'HTTP::Message::decoded_content' tries to decompress content
# if response header contains 'Content-Encoding' field.
# However 'Furl' decompresses content by itself, 'Content-Encoding' field
# whose value is supported encoding type should be removed from response header.
my @removed = grep { ! m{\b(?:gzip|x-gzip|deflate)\b} } $cloned->header('content-encoding');
$cloned->header('content-encoding', \@removed);
$self->_as_http_response_internal([ $cloned->flatten ])->decoded_content(@_);
}
sub as_http_response {
my ($self) = @_;
return $self->_as_http_response_internal([ $self->headers->flatten ])
lib/Furl/Response.pm view on Meta::CPAN
my $self = shift;
return $self->{__charset} if exists $self->{__charset};
if ($self->can('content_charset')){
# To suppress:
# Parsing of undecoded UTF-8 will give garbage when decoding entities
local $SIG{__WARN__} = sub {};
my $charset = $self->content_charset;
$self->{__charset} = $charset;
return $charset;
}
lib/Furl/Response.pm view on Meta::CPAN
=item $res->body
Returns response body in scalar.
=item $res->decoded_content
This will return the content after any C<< Content-Encoding >> and charsets have been decoded. See L<< HTTP::Message >> for details
=item $res->request
Returns instance of L<Furl::Request> related this response.
view all matches for this distribution
view release on metacpan or search on metacpan
t/007_when_viewing_response_as_json.t view on Meta::CPAN
cmp_ok(ref($result) ? "it's a ref - " . ref($result) : "it's a scalar", 'eq', "it's a scalar", 'Result is a SCALAR and not a reference');
my $hash = eval { JSON->new->decode( $result ) } || {};
is_deeply($hash, $expected, "JSON decoded back to hash correctly");
$tests += 2;
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/FusionInventory/Agent/Tools/License.pm view on Meta::CPAN
my @bytes = @key_bytes[$first_byte .. $last_byte];
# return immediatly for null keys
return if all { $_ == 00 } @bytes;
# decoded product key
my @chars;
for (my $i = $chars_length - 1; $i >= 0; $i--) {
my $index = 0;
for (my $j = $bytes_length - 1; $j >= 0; $j--) {
lib/FusionInventory/Agent/Tools/License.pm view on Meta::CPAN
Returns a structured view of Adobe license without Sqlite.
=head2 decodeMicrosoftKey($string)
Return a decoded string from a binary binary microsoft product key (XP, office,
etc)
view all matches for this distribution
view release on metacpan or search on metacpan
0.09 2018-05-19
* Silence warning when using Mojolicious
Thanks to pplu and Grinnz for reporting it and the diagnosis
This addresses https://github.com/Corion/future-http/issues/2
* The response body is now always decoded like HTTP::Message->decoded_content
If you need access to the raw, undecoded content, please tell me
* Switch from including Test::HTTP::LocalServer to loading it as
a test prerequisite
0.08 2017-11-29
* 3xx status codes are not treated as errors anymore
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Future/Workflow/Pipeline.pm view on Meta::CPAN
return await $ua->GET( $url );
});
# A synchronous (in-process) stage; e.g. some HTML parsing
$pipeline->append_stage_sync( sub ($response) {
my $dom = Mojo::DOM->new( $response->decoded_content );
return $dom->at('div[id="main"]')->text;
});
# A detached (out-of-process/thread) stage; e.g. some silly CPU-intensive task
$pipeline->append_stage_detached( sub ($text) {
view all matches for this distribution
view release on metacpan or search on metacpan
htdocs/example_scripts/gbrowse_upload_data.pl view on Meta::CPAN
@id
]
);
my $response = $agent->request($request);
die $response->status_line unless $response->is_success;
my $content = $response->decoded_content;
my $cookie = $response->header('Set-cookie');
my ($used_id) = $cookie =~ /gbrowse_sess=([a-f0-9]+)/;
my $struct = from_json($content);
view all matches for this distribution