| 1 | package Lemonolap::Wrapperolap; | ||
| 2 | use strict; | ||
| 3 | use XML::Simple; | ||
| 4 | our $VERSION = '0.01'; | ||
| 5 | sub new { | ||
| 6 | my $class =shift; | ||
| 7 | my %args = @_; | ||
| 8 | my $file = $args{config}; | ||
| 9 | my $self; | ||
| 10 | my $config= XMLin ($file); | ||
| 11 | $self->{file} =$file; | ||
| 12 | $self->{config} = $config; | ||
| 13 | $self->{workflow}= $args{workflow}; | ||
| 14 | |||
| 15 | bless $self,$class; | ||
| 16 | return $self; | ||
| 17 | |||
| 18 | } | ||
| 19 | sub get_file_in { | ||
| 20 | my $self =shift; | ||
| 21 | my $phase =$self->{phase}; | ||
| 22 | return $self->{config}->{$phase}->{file_in}; | ||
| 23 | |||
| 24 | } | ||
| 25 | sub get_file_out { | ||
| 26 | my $self =shift; | ||
| 27 | my $phase =$self->{phase}; | ||
| 28 | return $self->{config}->{$phase}->{file_out}; | ||
| 29 | |||
| 30 | } | ||
| 31 | |||
| 32 | sub get_handler { | ||
| 33 | my $self =shift; | ||
| 34 | my $phase =$self->{phase}; | ||
| 35 | return $self->{config}->{$phase}->{handler}; | ||
| 36 | } | ||
| 37 | |||
| 38 | sub get_config { | ||
| 39 | my $self =shift; | ||
| 40 | my $phase =$self->{phase}; | ||
| 41 | return $self->{config}->{$phase}; | ||
| 42 | |||
| 43 | } | ||
| 44 | sub set_phase { | ||
| 45 | my $self =shift; | ||
| 46 | $self->{phase} = shift; | ||
| 47 | return 1; | ||
| 48 | } | ||
| 49 | sub run { | ||
| 50 | my $self =shift; | ||
| 51 | my %args = @_; | ||
| 52 | |||
| 53 | my @tab = @{$self->{workflow}}; | ||
| 54 | |||
| 55 | my $header =$args{header}; | ||
| 56 | foreach (@tab) { | ||
| 57 | $self->set_phase($_); | ||
| 58 | my $file = $self->get_file_in; | ||
| 59 | my $handler= $self->get_handler; | ||
| 60 | my $sortie =$self->get_file_out; | ||
| 61 | eval "use $handler;"; | ||
| 62 | my $hook =$handler->new (%args); | ||
| 63 | $hook->set_output($sortie); | ||
| 64 | $hook->apply(infile =>$file, | ||
| 65 | outfile =>$sortie, | ||
| 66 | header =>$header ) ; | ||
| 67 | } | ||
| 68 | return 1; | ||
| 69 | } | ||
| 70 | |||
| 71 | 1; | ||
| 72 | __END__ |