The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

POEx::Trait::DeferredRegistration - Provides deferred POE Session registration for SessionInstantiation objects

VERSION

version 1.102770

SYNOPSIS

    class My::Session
    {
        use POEx::Trait::DeferredRegistration;
        use POEx::Role::SessionInstantiation
            traits => [ 'POEx::Trait::DeferredRegistration' ];

        with 'POEx::Role::SessionInstantiation';

        ....
    }

    ...
    # inside some event handler
    method some_event_handler is Event
    {
        my $session = My::Session->new();
        $self->yield('activate_session', session => $session);
    }

    method activate_session (DoesSessionInstantiation :$session) is Event
    {
        # Fiddle with the guts of $session prior to registration
        ...
        
        $session->register();

        # $session's _start will now be invoked within a POE context
    }

DESCRIPTION

POEx::Trait::DeferredRegistration provides a mechanism for instantiating sessions without registering with POE immediately. It does this by reaching into the guts of POEx::Role::SessionInstantiation::Meta::Session::Magic and preventing BUILD from calling _poe_register (which calls session_alloc).

Simply call register on the session object at the appropriate time and it will spring to life.

PARAMETERS

You can also alter the name of the name of the 'register' method by providing a 'method_name' argument along with the trait name:

    use POEx::Role::SessionInstantiation
        traits =>
            ['POEx::Trait::DeferredRegistration' => { method_name => 'foo'}];
    ....
    $session->foo();
    # calls _poe_register()

AUTHOR

Nicholas Perez <nperez@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2010 by Infinity Interactive.

This is free software, licensed under:

  The GNU General Public License, Version 3, June 2007