| 1 | package Zing::Zang::Spawner; | ||
| 2 | |||
| 3 | use 5.014; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | use registry; | ||
| 9 | use routines; | ||
| 10 | |||
| 11 | use Data::Object::Class; | ||
| 12 | use Data::Object::ClassHas; | ||
| 13 | |||
| 14 | extends 'Zing::Spawner'; | ||
| 15 | |||
| 16 | our $VERSION = '0.11'; # VERSION | ||
| 17 | |||
| 18 | # ATTRIBUTES | ||
| 19 | |||
| 20 | has 'on_perform' => ( | ||
| 21 | is => 'ro', | ||
| 22 | isa => 'Maybe[CodeRef]', | ||
| 23 | opt => 1, | ||
| 24 | ); | ||
| 25 | |||
| 26 | has 'on_receive' => ( | ||
| 27 | is => 'ro', | ||
| 28 | isa => 'Maybe[CodeRef]', | ||
| 29 | opt => 1, | ||
| 30 | ); | ||
| 31 | |||
| 32 | has 'queues' => ( | ||
| 33 | is => 'ro', | ||
| 34 | isa => 'ArrayRef[Str]', | ||
| 35 | req => 1, | ||
| 36 | ); | ||
| 37 | |||
| 38 | # METHODS | ||
| 39 | |||
| 40 | method receive(@args) { | ||
| 41 | return $self if !$self->on_receive; | ||
| 42 | |||
| 43 | $self->on_receive->($self, @args); | ||
| 44 | |||
| 45 | return $self; | ||
| 46 | } | ||
| 47 | |||
| 48 | method perform(@args) { | ||
| 49 | return $self if !$self->on_perform; | ||
| 50 | |||
| 51 | $self->on_perform->($self, @args); | ||
| 52 | |||
| 53 | return $self; | ||
| 54 | } | ||
| 55 | |||
| 56 | 1; | ||
| 57 | |||
| 58 | =encoding utf8 | ||
| 59 | |||
| 60 | =head1 NAME | ||
| 61 | |||
| 62 | Zing::Zang::Spawner - Process Spawner | ||
| 63 | |||
| 64 | =cut | ||
| 65 | |||
| 66 | =head1 ABSTRACT | ||
| 67 | |||
| 68 | Process Spawner Implementation | ||
| 69 | |||
| 70 | =cut | ||
| 71 | |||
| 72 | =head1 SYNOPSIS | ||
| 73 | |||
| 74 | use Zing::Zang::Spawner; | ||
| 75 | |||
| 76 | my $zang = Zing::Zang::Spawner->new( | ||
| 77 | queues => ['launch'], | ||
| 78 | ); | ||
| 79 | |||
| 80 | # $zang->execute; | ||
| 81 | |||
| 82 | =cut | ||
| 83 | |||
| 84 | =head1 DESCRIPTION | ||
| 85 | |||
| 86 | This package provides a L<Zing::Spawner> which uses callbacks and doesn't need | ||
| 87 | to be subclassd. It supports providing a list of queues to listen to which will | ||
| 88 | fork a process that loads, instantiates and executes schemes recevied. | ||
| 89 | |||
| 90 | =cut | ||
| 91 | |||
| 92 | =head1 INHERITS | ||
| 93 | |||
| 94 | This package inherits behaviors from: | ||
| 95 | |||
| 96 | L<Zing::Spawner> | ||
| 97 | |||
| 98 | =cut | ||
| 99 | |||
| 100 | =head1 LIBRARIES | ||
| 101 | |||
| 102 | This package uses type constraints from: | ||
| 103 | |||
| 104 | L<Zing::Types> | ||
| 105 | |||
| 106 | =cut | ||
| 107 | |||
| 108 | =head1 ATTRIBUTES | ||
| 109 | |||
| 110 | This package has the following attributes: | ||
| 111 | |||
| 112 | =cut | ||
| 113 | |||
| 114 | =head2 on_perform | ||
| 115 | |||
| 116 | on_perform(Maybe[CodeRef]) | ||
| 117 | |||
| 118 | This attribute is read-only, accepts C<(Maybe[CodeRef])> values, and is optional. | ||
| 119 | |||
| 120 | =cut | ||
| 121 | |||
| 122 | =head2 on_receive | ||
| 123 | |||
| 124 | on_receive(Maybe[CodeRef]) | ||
| 125 | |||
| 126 | This attribute is read-only, accepts C<(Maybe[CodeRef])> values, and is optional. | ||
| 127 | |||
| 128 | =cut | ||
| 129 | |||
| 130 | =head2 queues | ||
| 131 | |||
| 132 | queues(ArrayRef[Str]) | ||
| 133 | |||
| 134 | This attribute is read-only, accepts C<(ArrayRef[Str])> values, and is required. | ||
| 135 | |||
| 136 | =cut | ||
| 137 | |||
| 138 | =head1 AUTHOR | ||
| 139 | |||
| 140 | Al Newkirk, C<awncorp@cpan.org> | ||
| 141 | |||
| 142 | =head1 LICENSE | ||
| 143 | |||
| 144 | Copyright (C) 2011-2019, Al Newkirk, et al. | ||
| 145 | |||
| 146 | This is free software; you can redistribute it and/or modify it under the terms | ||
| 147 | of the The Apache License, Version 2.0, as elucidated in the L<"license | ||
| 148 | file"|https://github.com/iamalnewkirk/zing/blob/master/LICENSE>. | ||
| 149 | |||
| 150 | =head1 PROJECT | ||
| 151 | |||
| 152 | L<Wiki|https://github.com/iamalnewkirk/zing/wiki> | ||
| 153 | |||
| 154 | L<Project|https://github.com/iamalnewkirk/zing> | ||
| 155 | |||
| 156 | L<Initiatives|https://github.com/iamalnewkirk/zing/projects> | ||
| 157 | |||
| 158 | L<Milestones|https://github.com/iamalnewkirk/zing/milestones> | ||
| 159 | |||
| 160 | L<Contributing|https://github.com/iamalnewkirk/zing/blob/master/CONTRIBUTE.md> | ||
| 161 | |||
| 162 | L<Issues|https://github.com/iamalnewkirk/zing/issues> | ||
| 163 | |||
| 164 | =cut |