Eixo-Rest
view release on metacpan or search on metacpan
lib/Eixo/Rest/Api.pm view on Meta::CPAN
package Eixo::Rest::Api;
use strict;
use Eixo::Base::Clase;
use Data::Dumper;
use Attribute::Handlers;
use Eixo::Rest::Client;
use Carp;
use Eixo::Rest::Uri;
my $JOB_ID = 1;
has (
client => undef,
jobs=>[],
);
sub AUTOLOAD{
my ($self, @args) = @_;
my ($method) = our $AUTOLOAD =~ /\:\:(\w+)$/;
if($method =~ /^get|^post|^patch|^delete|^update|^put|^head/){
@args = $self->__analyzeRequest($method, @args);
}
else{
die("Unknown REST method " . $method);
}
$self->client->$method(@args);
}
sub DESTROY {}
sub initialize{
my ($self, $endpoint, %opts) = @_;
$self->client(
Eixo::Rest::Client->new($endpoint, %opts)
);
$self->SUPER::initialize(%opts);
$self;
}
sub produce{
my ($self, $class, %args) = @_;
$self->__loadProduct($class);
$class->new(
api=>$self,
%args
)
}
sub newJob{
my ($self, $request, $id) = @_;
push @{$self->jobs}, $request;
$self;
}
sub jobFinished{
my ($self, $request) = @_;
$self->jobs([ grep {
$_ != $request
} @{$self->jobs} ] );
}
sub waitForJob{
my ($self, $job_id) = @_;
$self->waitForJobs($job_id);
}
sub waitForJobs{
my ($self, $id) = @_;
while(scalar(@{$self->jobs})){
if($id){
return unless(scalar(grep { $_->job_id == $id } @{$self->jobs}));
}
foreach my $job (@{$self->jobs}){
$job->process;
select(undef, undef, undef, 0.05);
( run in 1.129 second using v1.01-cache-2.11-cpan-13bb782fe5a )