Games-Lacuna-Client
view release on metacpan or search on metacpan
lib/Games/Lacuna/Client/RPC.pm view on Meta::CPAN
package Games::Lacuna::Client::RPC;
{
$Games::Lacuna::Client::RPC::VERSION = '0.003';
}
use 5.0080000;
use strict;
use warnings;
use Carp 'croak';
use Scalar::Util 'weaken';
use Time::HiRes qw( sleep );
use Games::Lacuna::Client;
use IO::Interactive qw( is_interactive );
our @CARP_NOT = qw(
Games::Lacuna::Client
Games::Lacuna::Client::Alliance
Games::Lacuna::Client::Body
Games::Lacuna::Client::Buildings
Games::Lacuna::Client::Captcha
Games::Lacuna::Client::Empire
Games::Lacuna::Client::Inbox
Games::Lacuna::Client::Map
Games::Lacuna::Client::Stats
);
use Exception::Class (
'LacunaException',
'LacunaRPCException' => {
isa => 'LacunaException',
description => 'The RPC service generated an error.',
fields => [qw(code text)],
},
);
use namespace::clean;
use Moose;
extends 'JSON::RPC::LWP';
has client => (
is => 'ro',
isa => 'Games::Lacuna::Client',
required => 1,
weak_ref => 1,
);
# was always called with ( id => "1" )
has '+id_generator' => (
default => sub{sub{1}},
);
around call => sub {
my $orig = shift;
my $self = shift;
my $uri = shift;
my $method = shift;
my $params = shift;
# Call the method. If a Captcha error is returned, attempt to handle it
# and re-call the method, up to 3 times
my $trying = 1;
my $is_interactive = is_interactive();
my $try_captcha = $self->{client}->open_captcha || $self->{client}->prompt_captcha;
my $captcha_attempts = 0;
my $res;
( run in 2.610 seconds using v1.01-cache-2.11-cpan-8f98c5d2c55 )