Launcher::Cascade::Simple - a simple implementation for a Launcher, based on callbacks.
use Launcher::Cascade::Simple; sub test_method { my $self = shift; if ( ... ) { return SUCCESS } elsif ( ... ) { return FAILURE } else { return UNDEFINED } } sub launch_method { my $self = shift; ... } my $launcher = new Launcher::Cascade::Simple -name => 'simple', -test_hook => \&test_method, -launch_hook => \&launch_method, ;
A Launcher::Cascade class only has to provide methods to launch() a process, and to test() whether it succeeded. One way is to create a subclass of Launcher::Cascade::Base and to overload the methods there.
Launcher::Cascade::Base
For simple cases, however, it might be easier to instantiate a Launcher::Cascade::Simple and provide it with two callbacks, one for launching and one for testing.
Launcher::Cascade::Simple
Launcher::Cascade::Simple exports the constant methods SUCCESS, FAILURE and UNDEFINED as defined in Launcher::Cascade::Base. These can be used as constants in the fonction given to test_hook().
SUCCESS
FAILURE
UNDEFINED
Attributes are accessed through accessor methods. These methods, when called without an argument, will return the attribute's value. With an argument, they will set the attribute's value to that argument, and return the former value.
Callbacks that will be invoked when calling the launch() and test() methods, respectively. The callbacks will receive whatever arguments were given to launch() or test(), including the reference to the object itself (the callbacks can thus be considered as methods).
In addition, test_hook() can be given a arrayref of callbacks, in order to implement several tests that depend on each other, as in:
$launcher->test_hook([sub { ... }, sub { ... }, sub { ... }]);
In that case, test() will invoke each callback in turn. If it fails, test() will immediately return failure. If it succeeds, test() will proceed with the next callback. If it is undefined, test() will retry the same callback at its next attempt, if max_retries() is not null.
This method overrides that from Launcher::Cascade::Base and invokes the callback given in the launch_hook() attribute.
This method overrides that from Launcher::Cascade::Base and either,
invokes the one callback given in the test_hook() attribute,
or invokes, one after another, the callbacks given in the test_hook() attribute, until one of them fails or all of them succeed. If the result of the test is undefined, the same callback will be invoked at next attempt, provided that max_retries() is not null.
Reset the object's status so that it can be run again.
Cédric Bouvier <cbouvi@cpan.org>
<cbouvi@cpan.org>
Copyright (C) 2006 Cédric Bouvier, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in 'Cédric'. Assuming CP1252
To install Launcher::Cascade, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Launcher::Cascade
CPAN shell
perl -MCPAN -e shell install Launcher::Cascade
For more information on module installation, please visit the detailed CPAN module installation guide.