BlueT - Matthew Lien - 練喆明 > AnyEvent-CallbackStack-0.09 > AnyEvent::CallbackStack

Download:
AnyEvent-CallbackStack-0.09.tgz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.09   Source   Latest Release: AnyEvent-CallbackStack-0.10

NAME ^

AnyEvent::CallbackStack - Convert nested callback into easy-to-read-write-and-maintain serial/procedural coding style by using Callback Stack.

SYNOPSIS ^

Use AnyEvent::CallbackStack with the following style.

        use feature 'say';
        use AnyEvent::CallbackStack;
        
        my $cs = AnyEvent::CallbackStack->new();
        $cs->start( %foo );
        $cs->add( sub {
                do_something;
                $cs->next( $bar, $yohoo );
        });
        
        $cv = $cs->last;
        return $cv;

# or

        http_get http://BlueT.org => sub { $cs->start($_[0]) };
        $cs->add( sub { say $_[0]->recv } );

# or

        $cs->add( sub { say 'I got the ball'; $cs->next( $_[0]->recv ); } )
        print 'Your name please?: ';
        chomp(my $in = <STDIN>);
        $cs->start($in);
        $cs->add( sub { say "Lucky you, $_[0]->recv" } );

# or

        my $cs = AE::CS;

METHODS ^

new

No paramater needed.

        my $cs = new AnyEvent::CallbackStack;

start

Start and walk through the Callback Stack from step 0.

        $cs->start( 'foo' );

add

Add (append) callback into the Callback Stack.

        $cs->add( $code_ref );

next

Check out from the current step and pass value to the next callback in callback stack.

        $cs->next( @result );

IMPORTANT: Remember that only if you call this method, the next callback in stack will be triggered.

last

Get the very last AnyEvent::CondVar object.

Usually it's called when you are writing a module and need to return it to your caller.

        my $cv = $cs->last;
        # or
        return $cs->last;

step

Experimental.

Start the callback flow from the specified step.

        $cs->step( 3, @data );

cbq

Experimental.

Callback Queue Getter/Setter.

Don't use this directly unless you really know what you're doing.

        my @cbq = $cs->cbq;
        $cs->cbq( AE::cv );

current_step

Experimental.

'Current Step Counter' Getter/Setter.

Don't use this directly unless you really know what you're doing.

        my $curr_step = $cs->current_step;
        $cs->current_step( 0 );

SHORTCUT AE::CS API ^

Inspired by AE. Starting with version 0.05, AnyEvent::CallbackStack officially supports a second, much simpler in name, API that is designed to reduce the typing.

There is No Magic like what AE has on reducing calling and memory overhead.

See the AE::CS manpage for details.

        my $cs = AE::CS;

AUTHOR ^

BlueT - Matthew Lien - 練喆明, <BlueT at BlueT.org>

BUGS ^

Please report any bugs or feature requests to bug-anyevent-callbackstack at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=AnyEvent-CallbackStack. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT ^

You can find documentation for this module with the perldoc command.

    perldoc AnyEvent::CallbackStack

You can also look for information at:

ACKNOWLEDGEMENTS ^

LICENSE AND COPYRIGHT ^

Copyright 2012 BlueT - Matthew Lien - 練喆明.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

syntax highlighting: