Rocco Caputo > Reflex > Reflex::Role::Recving

Download:
Reflex-0.099.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.099   Source  

NAME ^

Reflex::Role::Recving - Mix standard send/recv code into a class.

VERSION ^

This document describes version 0.099, released on April 21, 2013.

SYNOPSIS ^

This UDP echo service comes from a more complete program, eg/eg-06-moose-roles.pl in Reflex's tarball.

TODO - New!

        package Reflex::UdpPeer::Echo;
        use Moose;
        with 'Reflex::Role::UdpPeer';

        sub on_udppeer_datagram {
                my ($self, $datagram) = @_;
                my $octets = $datagram->octets();

                if ($octets =~ /^\s*shutdown\s*$/) {
                        $self->destruct();
                        return;
                }

                $self->send(
                        octets => $octets,
                        peer   => $args->peer(),
                );
        }

        sub on_udppeer_error {
                my ($self, $args) = @_;
                warn "$args->{op} error $args->{errnum}: $args->{errstr}";
                $self->destruct();
        }

        1;

Programs may inherit from Reflex::UdpPeer rather than use the Moose role directly.

        package UdpEchoPeer;
        use base 'Reflex::UdpPeer';

        ...;

        1;

DESCRIPTION ^

Reflex::Role::UdpPeer implements non-blocking UDP socket work. This isn't very hard, since UDP sockets don't normally block anyway.

Public Attributes ^

port

Reflex::Role::UdpPeer will create a UDP socket during construction. The socket will be bound to the port (numeric or symbolic name) specified in the "port" attribute.

This may change in the future. Reflex really should be letting you create and provide your own handle, via a "handle" attribute, bound and otherwise set up how you like it.

max_datagram_size

"max_datagram_size" sets the limit for recv() calls. It defaults to 16KB (16384). This may change in the future.

Public Methods ^

send

Reflex::Role::UdpPeer's send() is a wrapper around Perl's built-in send() function. It checks the return value, and it will emit() an "error" message if send() fails.

This may also change, as the conventions for failure events solidify. Your feedback will help expedite the solidification.

destruct

destruct() clears the UDP peer's "handle" attribute and performs other cleanup to shut down the object.

The name will probably change to stop() or shutdown() as naming conventions standardize.

Public Events ^

datagram

Reflex::Role::UdpPeer emits "datagram" events when datagrams arrive. These events include two named values: "datagram" contains the data returned by recv(). "remote_addr" holds the datagram sender's packed address.

error

Reflex::Role::UdpPeer will emit() an "error" event if send() fails. It follows a standard convention for reporting errors or failures. Errors include three fields: "errfun" describes the function that failed, generally "send" or "recv". "errnum" and "errstr" hold the numeric and stringified versions of $! at the time of the failure.

Programs should not examine $! directly, as the value of this global special variable may have changed between the time of failure and the time of callback.

Reflex generally uses "failure" rather than "error" to indicate failures. This "error" event may be renamed later to conform with that emerging conventino.

EXAMPLES ^

eg/eg-04-inheritance.pl inherits from Reflex::UdpPeer.

eg/eg-05-composition.pl uses a Reflex::UdpPeer object as a helper, and composes with it in a has-a relationship.

eg/eg-06-moose-roles.pl composes an ojbect with Reflex::Role::UdpPeer.

SEE ALSO ^

Please see those modules/websites for more information related to this module.

BUGS AND LIMITATIONS ^

You can make new bug reports, and view existing ones, through the web interface at http://rt.cpan.org/Public/Dist/Display.html?Name=Reflex.

AUTHOR ^

Rocco Caputo <rcaputo@cpan.org>

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2013 by Rocco Caputo.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

AVAILABILITY ^

The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit http://www.perl.com/CPAN/ to find a CPAN site near you, or see https://metacpan.org/module/Reflex/.

DISCLAIMER OF WARRANTY ^

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

syntax highlighting: