| 1 | package Zing::Launcher; | ||
| 2 | |||
| 3 | use 5.014; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | use registry 'Zing::Types'; | ||
| 9 | use routines; | ||
| 10 | |||
| 11 | use Data::Object::Class; | ||
| 12 | use Data::Object::Space; | ||
| 13 | |||
| 14 | extends 'Zing::Worker'; | ||
| 15 | |||
| 16 | our $VERSION = '0.26'; # VERSION | ||
| 17 | |||
| 18 | # METHODS | ||
| 19 | |||
| 20 | method handle(Str $name, HashRef $data) { | ||
| 21 | return $self if !$data->{scheme}; | ||
| 22 | |||
| 23 | my $class = $data->{scheme}[0]; | ||
| 24 | my $space = Data::Object::Space->new($class); | ||
| 25 | my $build = $space->build(@{$data->{scheme}[1]}); | ||
| 26 | |||
| 27 | $build->execute for 1..($data->{scheme}[2] || 1); | ||
| 28 | |||
| 29 | return $self; | ||
| 30 | } | ||
| 31 | |||
| 32 | 1; | ||
| 33 | |||
| 34 | =encoding utf8 | ||
| 35 | |||
| 36 | =head1 NAME | ||
| 37 | |||
| 38 | Zing::Launcher - Scheme Launcher | ||
| 39 | |||
| 40 | =cut | ||
| 41 | |||
| 42 | =head1 ABSTRACT | ||
| 43 | |||
| 44 | Scheme Launching Worker Process | ||
| 45 | |||
| 46 | =cut | ||
| 47 | |||
| 48 | =head1 SYNOPSIS | ||
| 49 | |||
| 50 | package Launcher; | ||
| 51 | |||
| 52 | use parent 'Zing::Launcher'; | ||
| 53 | |||
| 54 | sub queues { | ||
| 55 | ['schemes'] | ||
| 56 | } | ||
| 57 | |||
| 58 | package main; | ||
| 59 | |||
| 60 | my $launcher = Launcher->new; | ||
| 61 | |||
| 62 | # $launcher->execute; | ||
| 63 | |||
| 64 | =cut | ||
| 65 | |||
| 66 | =head1 DESCRIPTION | ||
| 67 | |||
| 68 | This package provides a worker process which loads, instantiates, and executes | ||
| 69 | schemes received as messages. | ||
| 70 | |||
| 71 | =cut | ||
| 72 | |||
| 73 | =head1 INHERITS | ||
| 74 | |||
| 75 | This package inherits behaviors from: | ||
| 76 | |||
| 77 | L<Zing::Worker> | ||
| 78 | |||
| 79 | =cut | ||
| 80 | |||
| 81 | =head1 LIBRARIES | ||
| 82 | |||
| 83 | This package uses type constraints from: | ||
| 84 | |||
| 85 | L<Zing::Types> | ||
| 86 | |||
| 87 | =cut | ||
| 88 | |||
| 89 | =head1 METHODS | ||
| 90 | |||
| 91 | This package implements the following methods: | ||
| 92 | |||
| 93 | =cut | ||
| 94 | |||
| 95 | =head2 handle | ||
| 96 | |||
| 97 | handle(Str $name, HashRef $data) : Object | ||
| 98 | |||
| 99 | The handle method is executed whenever the process receive a new message, and | ||
| 100 | receives the queue name and data as arguments. | ||
| 101 | |||
| 102 | =over 4 | ||
| 103 | |||
| 104 | =item handle example #1 | ||
| 105 | |||
| 106 | # given: synopsis | ||
| 107 | |||
| 108 | $launcher->handle('schemes', { scheme => ['MyApp', [], 1] }); | ||
| 109 | |||
| 110 | =back | ||
| 111 | |||
| 112 | =over 4 | ||
| 113 | |||
| 114 | =item handle example #2 | ||
| 115 | |||
| 116 | # given: synopsis | ||
| 117 | |||
| 118 | $launcher->handle('schemes', { scheme => ['MyApp', [], 4] }); | ||
| 119 | |||
| 120 | =back | ||
| 121 | |||
| 122 | =cut | ||
| 123 | |||
| 124 | =head1 AUTHOR | ||
| 125 | |||
| 126 | Al Newkirk, C<awncorp@cpan.org> | ||
| 127 | |||
| 128 | =head1 LICENSE | ||
| 129 | |||
| 130 | Copyright (C) 2011-2019, Al Newkirk, et al. | ||
| 131 | |||
| 132 | This is free software; you can redistribute it and/or modify it under the terms | ||
| 133 | of the The Apache License, Version 2.0, as elucidated in the L<"license | ||
| 134 | file"|https://github.com/iamalnewkirk/zing/blob/master/LICENSE>. | ||
| 135 | |||
| 136 | =head1 PROJECT | ||
| 137 | |||
| 138 | L<Wiki|https://github.com/iamalnewkirk/zing/wiki> | ||
| 139 | |||
| 140 | L<Project|https://github.com/iamalnewkirk/zing> | ||
| 141 | |||
| 142 | L<Initiatives|https://github.com/iamalnewkirk/zing/projects> | ||
| 143 | |||
| 144 | L<Milestones|https://github.com/iamalnewkirk/zing/milestones> | ||
| 145 | |||
| 146 | L<Contributing|https://github.com/iamalnewkirk/zing/blob/master/CONTRIBUTE.md> | ||
| 147 | |||
| 148 | L<Issues|https://github.com/iamalnewkirk/zing/issues> | ||
| 149 | |||
| 150 | =cut |