Event::ExecFlow::Job::Code - Execute a closure


Event-ExecFlow documentation Contained in the Event-ExecFlow distribution.

Index


Code Index:

NAME

Top

Event::ExecFlow::Job::Code - Execute a closure

SYNOPSIS

Top

  Event::ExecFlow::Job::Code->new (
    code     => Closure to execute,
    ...
    Event::ExecFlow::Job attributes
  );

DESCRIPTION

Top

Use this module for execution of arbitrary Perl code (passed as a closure) inside an Event::ExecFlow.

OBJECT HIERARCHY

Top

  Event::ExecFlow

  Event::ExecFlow::Job
  +--- Event::ExecFlow::Job::Code

  Event::ExecFlow::Frontend
  Event::ExecFlow::Callbacks

ATTRIBUTES

Top

Attributes can by accessed at runtime using the common get_ATTR(), set_ATTR() style accessors.

[ FIXME: describe all attributes in detail ]

METHODS

Top

[ FIXME: describe all methods in detail ]

AUTHORS

Top

 Jörn Reder <joern at zyn dot de>

COPYRIGHT AND LICENSE

Top


Event-ExecFlow documentation Contained in the Event-ExecFlow distribution.

package Event::ExecFlow::Job::Code;

use base qw( Event::ExecFlow::Job );

use strict;

sub get_exec_type               { "sync" }
sub get_type                    { "code" }

sub get_code                    { shift->{code}                         }
sub set_code                    { shift->{code}                 = $_[1] }

sub new {
    my $class = shift;
    my %par = @_;
    my ($code) = $par{'code'};

    my $self = $class->SUPER::new(@_);

    $self->set_code($code);

    return $self;
}

sub execute {
    my $self = shift;
    
    my $code = $self->get_code;
    
    eval { $code->($self) };
    $self->set_error_message($@) if $@;
    
    $self->execution_finished;
    
    1;
}

sub cancel {
    my $self = shift;

    $self->set_cancelled(1);

    1;
}

sub pause_job {
    my $self = shift;

    1;
}

sub backup_state {
    my $self = shift;
    
    my $data_href = $self->SUPER::backup_state();
    
    delete $data_href->{code};
    
    return $data_href;
}

1;

__END__