AEAE::Command - a base class for an asynchroneous command.
jerome@eteve.net
Use this class as a base class when you wand to implement an asynchroneous command usable by AEAE::Service.
You only have to inherit from this class and implement the methods _doItReal and (eventually) _killHandler .
See those methods for more details.
See AEAE::CommandExample for a simple example.
Always override this method in subclasses in this way:
sub new{ my ($class) = @_ ;
my $self = $class->SUPER::new(@_); bless $self, $class ; return $self ; }
YOU CANNOT DO ANOTHER WAY. Any attempt to make another constructor will fail.
Get/Set the pid of the process running this command.
Get the standard ouput content of this command.
Usage:
my $stdout = $cmd->getSTDOUT();
Same as getSTDOUT but for STDERR
Returns true if is locked, false otherwise. Locked means that the process is not finished yet.
Returns true when it is done.
Set to true the done status. Can be used once.
Internal use.
Returns false if the command is a real one.
Use this to specifie the percentage of advance of this process.
If an error occurred, return the associated message. Otherwise, return an empty string.
Returns the step where the command is, between 0 and 100.
Kill yourself !!
Safely execute the nested _doItReal method.
Overide this method in subclasses. This is the main method executing the action to be made asynchroneous.
You must implement this method as a regular synchroneous procedure. You cannot return anything.
Within this method, you can (and must) access the current command to indicate the framework where you are in your procedure. For instance, if you are at 50% done, call :
$AEAE::Command::processCommand->oneStep(50);
Example of implementation:
sub _doItReal{ my $self = shift ; my $arg1 = shift ; my $arg2 = shift ; # ... my $i = 0 ; print "Ca commence !\n"; while( $i < 101){ $AEAE::Command::processCommand->oneStep($i); print "Step ".$i."\n"; $i += 1 ; select(undef, undef, undef, 0.25); } print "C'est fini !\n"; }
Called on myself when this command receive the order to suicide. Implement here release of ressources, termination of other process etc..
This method is called in the same memory space of the launched command. That means it is the same memory space as you are in the _doItReal method. Hence, any values setted in memory (for instance in $self->...) within the _doItReal method will be available here also.
Cleans the system ressources associated with this command. Implieds the command is done. Otherwise do nothing.
To install AEAE, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AEAE
CPAN shell
perl -MCPAN -e shell install AEAE
For more information on module installation, please visit the detailed CPAN module installation guide.