This is a object module used by Stem Cells and objects to detect when a set of asynchronous events have finished. It is constructed by an owner object which then stores it in itselt. Gather objects are initialized with a set of keys to be gathered. When the owner object is notified of an event, it calls the gathered method of the gather object with a list of keys. When all of the keys are gathered, a callback is made to the owner object. An optional timeout is available which will also generate a callback if the keys are not gathered in time.
gathered
use Stem::Gather ; # $self is the owner object that has already been created my $gather = Stem::Gather->new( 'object' => $self, 'keys' => [qw( msg1 msg2 )] ) ; $self->{'gather'} = $gather ; sub msg1_in { my( $self ) = @_ ; $self->{'gather'}->gathered( 'msg1' ) ; } sub msg2_in { my( $self ) = @_ ; $self->{'gather'}->gathered( 'msg2' ) ; } sub gather_done { my( $self ) = @_ ; print "we have gathered\n" ; }
Attribute - object
Attribute - keys
Attribute - gathered_method
Attribute - no_start
restart
Attribute - timeout
Attribute - timeout_method
This is the constructor method for Stem::Gather. It uses the standard Stem key/value API with the
This method is called to start up the gather object when it has already gathered all the keys, it has timed out or it was never started (the no_start attribute was enabled). It takes no arguments.
This method is passed a list of keys which will be added to the list to be watched for by the Stem::Gather object. The new keys are not looked for until a call to the restart method is made.
This method is called with a list of keys that are gathered. The keys that haven't been gathered before are marked as gathered. If there are no more keys to be gathered, the method in the gathered_method attribute is called in the owner object. You have to call the restart method on this gather object to use it again.You can pass this methods keys that have been gathered or are not even in the list to be gathered and they are ignored.
gathered_method
This method must be called if the owner object is being shut down or destroyed. It will cancel any pending timeout and break the link back to the owner object. The owner object can then be destroyed without leaking memory.
To install Stem, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Stem
CPAN shell
perl -MCPAN -e shell install Stem
For more information on module installation, please visit the detailed CPAN module installation guide.