Core/Handler/CommandHandler/InvokeStaticMethodHandler.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 60 CC 4 SCAR 21.5
CC
4
Cov
0%
process
20.0
new
2.0
BEGIN
2.0
CRAP 8.5
1 package Javonet::Core::Handler::CommandHandler::InvokeStaticMethodHandler;
2 use strict;
3 use warnings FATAL => 'all';
4 use lib 'lib';
5 use Moose;
6 use Nice::Try;
7 use aliased 'Javonet::Core::Exception::Exception' => 'Exception';
8 extends 'Javonet::Core::Handler::CommandHandler::AbstractCommandHandler';
9
10 sub new {
11 my $class = shift;
12 my $self = {
13 required_parameters_count => 2
14 };
15 return bless $self, $class;
16 }
17
18 sub process {
19 my ($self, $command) = @_;
20 try {
21 my $current_payload_ref = $command->{payload};
22 my @cur_payload = @$current_payload_ref;
23 my $parameters_length = @cur_payload;
24 if ($parameters_length < $self->{required_parameters_count}) {
25 die Exception->new("Exception: InvokeStaticMethod parameters mismatch");
26 }
27 my $clazz = $command->{payload}[0];
28 my $method_name = $command->{payload}[1];
29
30 if (my $method = $clazz->can($method_name)) {
31 if ($parameters_length == $self->{required_parameters_count}) {
32 return $method->();
33 }
34 else {
35 my @method_arguments;
36 for (my $i = 2; $i < $parameters_length; $i++) {
37 push @method_arguments, $command->{payload}[$i];
38 }
39 return $method->(@method_arguments);
40 }
41 }
42 else {
43 die Exception->new("Exception InvokeStaticMethod: method not found");
44 }
45 }
46 catch ($e){
47 return Exception->new($e);
48 }
49 }
50
51 1;