Richard Clamp > Class-Delay-0.02 > Class::Delay

Download:
Class-Delay-0.02.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.02   Source  

NAME ^

Class::Delay - delay method dispatch until a trigerring event

SYNOPSIS ^

 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" );

DESCRIPTION ^

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.

Options

The use statement takes the following options when generate the proxying behaviour.

methods

An array reference naming the methods to delay until a trigger event.

return

What a delayed method will return, defaults to 1.

release

An array reference naming the methods to ise as triggering events.

reorder

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.

AUTHOR ^

Richard Clamp <richardc@unixbeard.net>

COPYRIGHT ^

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.

syntax highlighting: