POEx::WorkerPool::Role::WorkerPool::Worker::GutsLoader - Implementation role of the Guts loader


POEx-WorkerPool documentation Contained in the POEx-WorkerPool distribution.

Index


Code Index:

NAME

Top

POEx::WorkerPool::Role::WorkerPool::Worker::GutsLoader - Implementation role of the Guts loader

VERSION

Top

version 1.102740

PUBLIC_ATTRIBUTES

Top

job_classes

 is: ro, isa: ArrayRef[ClassName], required: 1

These are the job classes should be loaded during init using Class::MOP::load_class

init

 is: ro, isa: CodeRef, lazy_build: 1

This holds the coderef that will be executed first to do any intitialization prior to building the Guts session

preamble

 is: ro, isa: CodeRef, lazy_build: 1

This holds the coderef that is responsible for stopping the forked POE::Kernel singleton

main

 is: ro, isa: CodeRef, lazy_build: 1

This holds the coderef that builds the actual Guts

prologue

 is: ro, isa: CodeRef, lazy_build: 1

This holds the coderef that calls run() on POE::Kernel to kickstart everything

loader

 is: ro, isa: CodeRef, lazy_build: 1

loader has the coderef that is used when building the POE::Wheel::Run instance inside of Worker's child_wheel attribute. The coderef is actually an aggregate of init, preamble, main, and prologue.

PROTECTED_METHODS

Top

_build_init

_build_init builds the coderef used for initialization of the job classes in the child process.

_build_preamble

_build_preamble builds the coderef that calls stop on POE::Kernel by default.

_build_main

_build_main builds the coderef that instantiates the Guts instance without any arguments. If Guts has other roles applied at compile time that require extra arguments, this method will need to be advised to provide those arguments to the constructor.

_build_prologue

_build_prologue builds the coderef that calls run() on POE::Kernel by default.

_build_loader

_build_loader builds the coderef that is passed to the POE::Wheel::Run constructor inside of Worker's child_wheel attribute builder. It creates a closure around lexical references to init, preamble, main, and prologue, that executes said coderefs in that order.

AUTHOR

Top

Nicholas R. Perez <nperez@cpan.org>

COPYRIGHT AND LICENSE

Top


POEx-WorkerPool documentation Contained in the POEx-WorkerPool distribution.

package POEx::WorkerPool::Role::WorkerPool::Worker::GutsLoader;
BEGIN {
  $POEx::WorkerPool::Role::WorkerPool::Worker::GutsLoader::VERSION = '1.102740';
}

#ABSTRACT: Implementation role of the Guts loader

use MooseX::Declare;

role POEx::WorkerPool::Role::WorkerPool::Worker::GutsLoader {
    use POE;
    use Class::MOP;
    use POEx::WorkerPool::Worker::Guts;
    use MooseX::Types;
    use MooseX::Types::Moose(':all');


    has job_classes => ( is => 'ro', isa => ArrayRef[ClassName], required => 1 );


    has init => ( is => 'ro', isa => CodeRef, lazy_build => 1 );


    has preamble => ( is => 'ro', isa => CodeRef, lazy_build => 1 );


    has main => ( is => 'ro', isa => CodeRef, lazy_build => 1 );


    has prologue => ( is => 'ro', isa => CodeRef, lazy_build => 1 );


    has loader => ( is => 'ro', isa => CodeRef, lazy_build => 1 );


    method _build_init {
        my $classes = $self->job_classes;
        return sub {
            Class::MOP::load_class($_) for @$classes;
        };
    }


    method _build_preamble {
        return sub {
            POE::Kernel->stop();
        };
    }


    method _build_main {
        return sub {
            POEx::WorkerPool::Worker::Guts->new();
        };
    }


    method _build_prologue {
        return sub {
            POE::Kernel->run();
        };
    }


    method _build_loader {
        my $init = $self->init;
        my $preamble = $self->preamble;
        my $main = $self->main;
        my $prologue = $self->prologue;

        return sub {
            $init->();
            $preamble->();
            $main->();
            $prologue->();
        };
    }
}

1;



__END__