Beta Shell
v2.0 ยท web2.us.cloudlogin.co
[FM]
[CMD]
[PHP]
[DB]
[INFO]
[SEC]
File Manager
~
/
usr
/
share
/
doc
/
perl-Test-LWP-UserAgent
/
examples
/
MyApp
Upload
3 items
Name
Size
Perms
Modified
Actions
[ .. / .. ]
Client.pm
834 B
-rw-r--r--
2017-05-18 00:46:46
Edit
Del
Editing: Client.pm
(834 B)
Path: /usr/share/doc/perl-Test-LWP-UserAgent/examples/MyApp/Client.pm
Back
package MyApp::Client; use strict; use warnings; use Moose; use LWP::UserAgent; use JSON::MaybeXS; has useragent => ( is => 'ro', isa => 'LWP::UserAgent', lazy => 1, default => sub { LWP::UserAgent->new }, ); sub get_indexes { my ($self, %args) = @_; my $user = $args{user}; # call our server to get the data my $url = "http://myserver.com/user/$user"; my $response = $self->useragent->get($url); if ($response->code ne '200' or $response->headers->content_type ne 'application/json') { warn "network timeout when fetching $url" if $response->decoded_content =~ /time(?:d )?out/; return; } # parse JSON data from response my $data = decode_json($response->decoded_content); return @{$data->{post_ids} // []}; } __PACKAGE__->meta->make_immutable;