| 1 | package ETLp::Plugin::Iterative::Perl; | ||
| 2 | |||
| 3 | use MooseX::Declare; | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | ETLp::Plugin::Iterative::Perl - Plugin for calling Perl subroutines | ||
| 8 | |||
| 9 | =cut | ||
| 10 | |||
| 11 | class ETLp::Plugin::Iterative::Perl extends ETLp::Plugin { | ||
| 12 | use File::Basename; | ||
| 13 | use UNIVERSAL::require; | ||
| 14 | use Try::Tiny; | ||
| 15 | |||
| 16 | =head1 METHODS | ||
| 17 | |||
| 18 | =head2 type | ||
| 19 | |||
| 20 | Registers the plugin type. | ||
| 21 | |||
| 22 | =head2 run | ||
| 23 | |||
| 24 | Executes the pipeline | ||
| 25 | |||
| 26 | =cut | ||
| 27 | |||
| 28 | sub type { | ||
| 29 | return 'perl'; | ||
| 30 | } | ||
| 31 | |||
| 32 | method run (Str $filename) { | ||
| 33 | my $item = $self->item; | ||
| 34 | my $package = $item->{package}; | ||
| 35 | my $sub = $item->{sub}; | ||
| 36 | my $params = $item->{params}; | ||
| 37 | my $interim_params; | ||
| 38 | |||
| 39 | my $call = "\$filename = ${package}::$sub($params)"; | ||
| 40 | $self->logger->debug("Call: $call"); | ||
| 41 | |||
| 42 | my $file_process = $self->audit->item->file_process; | ||
| 43 | |||
| 44 | try { | ||
| 45 | $package->require; | ||
| 46 | eval "$call" || | ||
| 47 | ETLpException->throw(error =>"Unable to run $call: $!"); | ||
| 48 | } catch { | ||
| 49 | my $error = $_; | ||
| 50 | |||
| 51 | if (ref $error) { | ||
| 52 | my $message = $call . ' ' . $error->error; | ||
| 53 | $file_process->update_message($message); | ||
| 54 | $file_process->update_status('failed'); | ||
| 55 | $error->rethrow; | ||
| 56 | } | ||
| 57 | |||
| 58 | my $message = $call . ' ' . $error; | ||
| 59 | |||
| 60 | $file_process->update_message($message); | ||
| 61 | $file_process->update_status('failed'); | ||
| 62 | |||
| 63 | $self->logger->debug("Not an ETLpException"); | ||
| 64 | ETLpException->throw(error => $error); | ||
| 65 | }; | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | =head1 LICENSE AND COPYRIGHT | ||
| 70 | |||
| 71 | Copyright 2010 Redbone Systems Ltd | ||
| 72 | |||
| 73 | This program is free software; you can redistribute it and/or modify it | ||
| 74 | under the terms of either: the GNU General Public License as published | ||
| 75 | by the Free Software Foundation; or the Artistic License. | ||
| 76 | |||
| 77 | The terms are in the LICENSE file that accompanies this application |