Sha256: 16c8e0e66534f0195c17e50b63b7be5e6034ba0a2dfce73c99b2461b184e42f7

Contents?: true

Size: 1.54 KB

Versions: 6

Compression:

Stored size: 1.54 KB

Contents

package Javonet::Core::Handler::CommandHandler::InvokeInstanceMethodHandler;
use aliased 'Javonet::Core::Handler::PerlHandler' => 'PerlHandler';
use strict;
use warnings FATAL => 'all';
use Moose;
use lib 'lib';
use lib 'data_seed';
use Nice::Try;
use aliased 'Javonet::Core::Handler::Exception' => 'Exception';
extends 'Javonet::Core::Handler::CommandHandler::AbstractCommandHandler';

sub new {
    my $class = shift;
    my $self = {
        required_parameters_count  => 2
    };
    return bless $self, $class;
}

sub process {
    my ($self, $command) = @_;
    try {
    my $current_payload_ref = $command->{payload};
    my @cur_payload = @$current_payload_ref;
    my $parameters_length = @cur_payload;
    if ($parameters_length < $self->{required_parameters_count}){
        die Exception->new("Exception: InvokeInstanceMethod parameters mismatch");
    }

    my $clazz_instance = $command->{payload}[0];
    my $method_name = $command->{payload}[1];
    if ($clazz_instance->can($method_name))
    {
        if ($parameters_length == $self->{required_parameters_count}) {
            return $clazz_instance->$method_name();
        }
        else{
            my @method_arguments;
            for (my $i=2; $i<$parameters_length; $i++){
                push @method_arguments, $command->{payload}[$i];
            }
            return $clazz_instance->$method_name(@method_arguments);
        }
    }
    else
    {
        die Exception->new("Exception InvokeInstanceMethod: method not found");
    }
    }
    catch ( $e ) {
        return $e ;
    }
}

1;

Version data entries

6 entries across 3 versions & 1 rubygems

Version Path
javonet-ruby-sdk-2.0.4 lib/javonet-ruby-sdk/Binaries/Perl/Linux/X64/lib/Javonet/Core/Handler/CommandHandler/InvokeInstanceMethodHandler.pm
javonet-ruby-sdk-2.0.4 lib/javonet-ruby-sdk/Binaries/Perl/MacOs/X64/lib/Javonet/Core/Handler/CommandHandler/InvokeInstanceMethodHandler.pm
javonet-ruby-sdk-2.0.1 lib/javonet-ruby-sdk/Binaries/Perl/Linux/X64/lib/Javonet/Core/Handler/CommandHandler/InvokeInstanceMethodHandler.pm
javonet-ruby-sdk-2.0.1 lib/javonet-ruby-sdk/Binaries/Perl/MacOs/X64/lib/Javonet/Core/Handler/CommandHandler/InvokeInstanceMethodHandler.pm
javonet-ruby-sdk-2.0.0 lib/javonet-ruby-sdk/Binaries/Perl/Linux/X64/lib/Javonet/Core/Handler/CommandHandler/InvokeInstanceMethodHandler.pm
javonet-ruby-sdk-2.0.0 lib/javonet-ruby-sdk/Binaries/Perl/MacOs/X64/lib/Javonet/Core/Handler/CommandHandler/InvokeInstanceMethodHandler.pm