Bio-KBase
view release on metacpan or search on metacpan
lib/Bio/KBase/IDServer/Service.pm view on Meta::CPAN
package Bio::KBase::IDServer::Service;
use Data::Dumper;
use Moose;
extends 'RPC::Any::Server::JSONRPC::PSGI';
has 'instance_dispatch' => (is => 'ro', isa => 'HashRef');
has 'user_auth' => (is => 'ro', isa => 'UserAuth');
has 'valid_methods' => (is => 'ro', isa => 'HashRef', lazy => 1,
builder => '_build_valid_methods');
our $CallContext;
our %return_counts = (
'kbase_ids_to_external_ids' => 1,
'external_ids_to_kbase_ids' => 1,
'register_ids' => 1,
'allocate_id_range' => 1,
'register_allocated_ids' => 0,
);
sub _build_valid_methods
{
my($self) = @_;
my $methods = {
'kbase_ids_to_external_ids' => 1,
'external_ids_to_kbase_ids' => 1,
'register_ids' => 1,
'allocate_id_range' => 1,
'register_allocated_ids' => 1,
};
return $methods;
}
sub call_method {
my ($self, $data, $method_info) = @_;
my ($module, $method) = @$method_info{qw(module method)};
my $ctx = Bio::KBase::IDServer::ServiceContext->new(client_ip => $self->_plack_req->address);
my $args = $data->{arguments};
if (@$args == 1 && ref($args->[0]) eq 'HASH')
{
my $actual_args = $args->[0]->{args};
my $token = $args->[0]->{auth_token};
$data->{arguments} = $actual_args;
# Service IDServerAPI does not require authentication.
}
my $new_isa = $self->get_package_isa($module);
no strict 'refs';
local @{"${module}::ISA"} = @$new_isa;
local $CallContext = $ctx;
my @result = $module->$method(@{ $data->{arguments} });
my $result;
if ($return_counts{$method} == 1)
{
$result = [[$result[0]]];
}
else
{
$result = \@result;
}
return $result;
}
( run in 0.469 second using v1.01-cache-2.11-cpan-39bf76dae61 )