Class::Delay - delay method dispatch until a trigerring event
package PrintOut; sub write { my $self = shift; print "printing: ", @_, "\n"; } sub flush { print "flushed\n"; } package DelayedPrint; use base 'PrintOut'; use Class::Delay methods => [ 'write' ], release => [ 'flush' ]; package main; DelayedPrint->write( "we'll write this later" ); # won't get through # to PrintOuts 'write' yet DelayedPrint->write( "this too" ); DelayedPrint->flush; # all of the queued call are dispatched DelayedPrint->write( "this won't be delayed" );
Class::Delay provides a mechanism for the delay of method dispatch until a triggering method is called.
You simply define a proxy class, and then call on the module to set up a set of methods that will defer.
The use statement takes the following options when generate the proxying behaviour.
An array reference naming the methods to delay until a trigger event.
What a delayed method will return, defaults to 1.
An array reference naming the methods to ise as triggering events.
A subroutine that will be passed the all the delayed messages as Class::Delay::Message objects. The routine should return these in the order that the messagages are to be deilvered.
For example, if we want to ensure our trigger event arrives before the rest of the events we may do something like this:
use Class::Delay methods => [qw( foo bar baz )], release => [qw( quux squirkle )], reorder => sub { sort { $b->is_trigger <=> $a->is_trigger } @_ };
An extended example of this module is in Mariachi::DBI which uses the module to delay database setup until the final of the database is known.
Richard Clamp <richardc@unixbeard.net>
Copyright (C) 2003 Richard Clamp. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Class::Delay, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::Delay
CPAN shell
perl -MCPAN -e shell install Class::Delay
For more information on module installation, please visit the detailed CPAN module installation guide.