NAME
Launcher::Cascade::Simple - a simple implementation for a Launcher, based on callbacks.
SYNOPSIS
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,
;
DESCRIPTION
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.
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.
Exports
- SUCCESS
- FAILURE
- UNDEFINED
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().
Attributes
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.
- launch_hook
- test_hook
-
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.
Methods
- launch
-
This method overrides that from
Launcher::Cascade::Base
and invokes the callback given in the launch_hook() attribute. - test
-
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
-
Reset the object's status so that it can be run again.
SEE ALSO
AUTHOR
Cédric Bouvier <cbouvi@cpan.org>
COPYRIGHT & LICENSE
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:
- Around line 183:
Non-ASCII character seen before =encoding in 'Cédric'. Assuming CP1252