| 1 | package ETLp::Plugin::Serial::Perl; | ||
| 2 | |||
| 3 | use MooseX::Declare; | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | ETLp::Plugin::Iterative::Perl- Plugin for calling the Perl Subroutines | ||
| 8 | |||
| 9 | =head1 METHODS | ||
| 10 | |||
| 11 | =head2 type | ||
| 12 | |||
| 13 | Registers the plugin type. | ||
| 14 | |||
| 15 | =head2 run | ||
| 16 | |||
| 17 | Executes the supplied perl code. | ||
| 18 | |||
| 19 | =head3 parameters | ||
| 20 | |||
| 21 | * none | ||
| 22 | |||
| 23 | =head3 returns | ||
| 24 | |||
| 25 | * void | ||
| 26 | |||
| 27 | =head1 ITEM | ||
| 28 | |||
| 29 | The item attribute hashref contains specific configuration information | ||
| 30 | for ETLp::Plugin::Serial::OS | ||
| 31 | |||
| 32 | =head2 command | ||
| 33 | |||
| 34 | The operating system command being run | ||
| 35 | |||
| 36 | =head2 timeout | ||
| 37 | |||
| 38 | This is an optional parameter that specifies when the command execution | ||
| 39 | should abort (in seconds). | ||
| 40 | |||
| 41 | =cut | ||
| 42 | |||
| 43 | class ETLp::Plugin::Serial::Perl extends ETLp::Plugin { | ||
| 44 | use autodie; | ||
| 45 | use UNIVERSAL::require; | ||
| 46 | use Try::Tiny; | ||
| 47 | |||
| 48 | sub type { | ||
| 49 | return 'perl'; | ||
| 50 | } | ||
| 51 | |||
| 52 | method run { | ||
| 53 | my $item = $self->item; | ||
| 54 | my $package = $item->{package}; | ||
| 55 | my $sub = $item->{sub}; | ||
| 56 | my $params = $item->{params}; | ||
| 57 | my $interim_params; | ||
| 58 | |||
| 59 | my $call = "${package}::$sub($params)"; | ||
| 60 | $self->logger->debug("Call: $call"); | ||
| 61 | |||
| 62 | $self->audit->item->update_message($call); | ||
| 63 | |||
| 64 | try { | ||
| 65 | $package->require; | ||
| 66 | eval "$call" || | ||
| 67 | ETLpException->throw(error =>"Unable to run $call: $!"); | ||
| 68 | } catch { | ||
| 69 | my $error = $_; | ||
| 70 | $self->logger->error($error); | ||
| 71 | my $error_message = $call . ' ' . $error; | ||
| 72 | ETLpException->throw(error => $error_message); | ||
| 73 | }; | ||
| 74 | } | ||
| 75 | |||
| 76 | } |