Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

anyevent::readme(3pm) [debian man page]

README(3pm)						User Contributed Perl Documentation					       README(3pm)

NAME
AnyEvent::Callback - callback aggregator for AnyEvent watchers. SYNOPSIS
use AnyEvent::Callback; # usually watchers are looked as: AE::something @args, sub { ... }; AE::something @args, sub { ... }, # result sub { ... }; # error use AnyEvent::Callback; AE::something @args, CB { ... }; AE::something @args, CB sub { ... }, # result sub { ... }; # error AE::something @args, CB sub { ... }, # result sub { ... }, # error sub { ... }; # anyway callback Callback hierarchy my $cbchild = $cb->CB(sub { ... }); ... $cbchild->error('error'); # will call $cb->error('error'); Inside Your callback You can: sub my_watcher { my $cb = pop; my @args = @_; # ... $cb->error( @error ); # error callback will be called # or: $cb->( $value ); # result callback will be called } Callbacks stack my $cbs = CBS; for (1 .. $n) { AE::something @args, $cbs->cb; } $cbs->wait(sub { for (@_) { if ($_->is_error) { # handle one error my @err = $_->errors; # or: my $errstr = $_->errstr; } else { # results my @res = $_->results; } } }); DESCRIPTION
The module allows You to create callback's hierarchy. Also the module groups error and result callbacks into one object. Also the module checks if one callback was called by watcher or not. If a watcher doesn't call result or error callback, error callback will be called automatically. Also the module checks if a callback was called reentrant. In the case the module will complain (using "carp" in Carp). If a watcher touches error callback and if superior didn't define error callback, the module will call error callback upwards hierarchy. Example: AE::something @args, CB &my_watcher, &on_error; sub on_error { } sub my_watcher { my $cb = pop; ... the_other_watcher $cb->CB( sub { # error callback wasn't defined my $cb = pop; ... yet_another_watcher1 $cb->CB( sub { my $cb = pop; ... $cb->( 123 ); # upwards callback }); yet_another_watcher2 $cb->CB( sub { my $cb = pop; ... $cb->error( 456 ); # on_error will be called }); }); } METHODS
'CODE' (overloaded fake method) $cb->( ... ); You can use the object as usually CODEREF. CB Creates new callback object that have binding on parent callback. my $new_cb = $cb->CB(sub { ... }); # the cb doesn't catch errors my $new_cb = CB(sub { ... }, sub { ... }); # the cb catches errors my $new_cb = $cb->CB(sub { ... }, sub { ... }); # the same error Calls error callback. If the object has no registered error callbacks, parent object's error callback will be called. $cb->error('WTF?'); COPYRIGHT AND LICENCE
Copyright (C) 2012 by Dmitry E. Oboukhov This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-06-30 README(3pm)

Check Out this Related Man Page

AnyEvent::XMPP::Parser(3pm)				User Contributed Perl Documentation			       AnyEvent::XMPP::Parser(3pm)

NAME
AnyEvent::XMPP::Parser - Parser for XML streams (helper for AnyEvent::XMPP) SYNOPSIS
use AnyEvent::XMPP::Parser; ... DESCRIPTION
This is a XMPP XML parser helper class, which helps me to cope with the XMPP XML. See also AnyEvent::XMPP::Writer for a discussion of the issues with XML in XMPP. METHODS
new This creates a new AnyEvent::XMPP::Parser and calls "init". set_stanza_cb ($cb) Sets the 'XML stanza' callback. $cb must be a code reference. The first argument to the callback will be this AnyEvent::XMPP::Parser instance and the second will be the stanzas root AnyEvent::XMPP::Node as first argument. If the second argument is undefined the end of the stream has been found. set_error_cb ($cb) This sets the error callback that will be called when the parser encounters an syntax error. The first argument is the exception and the second is the data which caused the error. set_stream_cb ($cb) This method sets the stream tag callback. It is called when the <stream> tag from the server has been encountered. The first argument to the callback is the AnyEvent::XMPP::Node of the opening stream tag. init This methods (re)initializes the parser. cleanup This methods removes all handlers. Use it to avoid circular references. nseq ($namespace, $tagname, $cmptag) This method checks whether the $cmptag matches the $tagname in the $namespace. $cmptag needs to come from the XML::Parser::Expat as it has some magic attached that stores the namespace. feed ($data) This method feeds a chunk of unparsed data to the parser. AUTHOR
Robin Redeker, "<elmex at ta-sa.org>", JID: "<elmex at jabber.org>" COPYRIGHT &; LICENSE Copyright 2007, 2008 Robin Redeker, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-03-19 AnyEvent::XMPP::Parser(3pm)
Man Page