| 1 | package Zing::Zang::Single; | ||
| 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::Single'; | ||
| 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 | # METHODS | ||
| 33 | |||
| 34 | method receive(@args) { | ||
| 35 | return $self if !$self->on_receive; | ||
| 36 | |||
| 37 | $self->on_receive->($self, @args); | ||
| 38 | |||
| 39 | return $self; | ||
| 40 | } | ||
| 41 | |||
| 42 | method perform(@args) { | ||
| 43 | return $self if !$self->on_perform; | ||
| 44 | |||
| 45 | $self->on_perform->($self, @args); | ||
| 46 | |||
| 47 | return $self; | ||
| 48 | } | ||
| 49 | |||
| 50 | 1; | ||
| 51 | =encoding utf8 | ||
| 52 | |||
| 53 | =head1 NAME | ||
| 54 | |||
| 55 | Zing::Zang::Single - Single-Task Process | ||
| 56 | |||
| 57 | =cut | ||
| 58 | |||
| 59 | =head1 ABSTRACT | ||
| 60 | |||
| 61 | Single-Task Process Implementation | ||
| 62 | |||
| 63 | =cut | ||
| 64 | |||
| 65 | =head1 SYNOPSIS | ||
| 66 | |||
| 67 | use Zing::Zang::Single; | ||
| 68 | |||
| 69 | my $zang = Zing::Zang::Single->new( | ||
| 70 | on_perform => sub { | ||
| 71 | my ($self) = @_; | ||
| 72 | |||
| 73 | $self->{performed}++ | ||
| 74 | } | ||
| 75 | ); | ||
| 76 | |||
| 77 | # $zang->execute; | ||
| 78 | |||
| 79 | =cut | ||
| 80 | |||
| 81 | =head1 DESCRIPTION | ||
| 82 | |||
| 83 | This package provides a standard L<Zing::Process> which uses callbacks and | ||
| 84 | doesn't need to be subclassd. It supports providing the standard process | ||
| 85 | C<perform> method as C<on_perform> and C<receive> method as C<on_receive> which | ||
| 86 | operate as expected. This process executes its loop only once. | ||
| 87 | |||
| 88 | =cut | ||
| 89 | |||
| 90 | =head1 INHERITS | ||
| 91 | |||
| 92 | This package inherits behaviors from: | ||
| 93 | |||
| 94 | L<Zing::Single> | ||
| 95 | |||
| 96 | =cut | ||
| 97 | |||
| 98 | =head1 LIBRARIES | ||
| 99 | |||
| 100 | This package uses type constraints from: | ||
| 101 | |||
| 102 | L<Zing::Types> | ||
| 103 | |||
| 104 | =cut | ||
| 105 | |||
| 106 | =head1 ATTRIBUTES | ||
| 107 | |||
| 108 | This package has the following attributes: | ||
| 109 | |||
| 110 | =cut | ||
| 111 | |||
| 112 | =head2 on_perform | ||
| 113 | |||
| 114 | on_perform(Maybe[CodeRef]) | ||
| 115 | |||
| 116 | This attribute is read-only, accepts C<(Maybe[CodeRef])> values, and is optional. | ||
| 117 | |||
| 118 | =cut | ||
| 119 | |||
| 120 | =head2 on_receive | ||
| 121 | |||
| 122 | on_receive(Maybe[CodeRef]) | ||
| 123 | |||
| 124 | This attribute is read-only, accepts C<(Maybe[CodeRef])> values, and is optional. | ||
| 125 | |||
| 126 | =cut | ||
| 127 | |||
| 128 | =head1 AUTHOR | ||
| 129 | |||
| 130 | Al Newkirk, C<awncorp@cpan.org> | ||
| 131 | |||
| 132 | =head1 LICENSE | ||
| 133 | |||
| 134 | Copyright (C) 2011-2019, Al Newkirk, et al. | ||
| 135 | |||
| 136 | This is free software; you can redistribute it and/or modify it under the terms | ||
| 137 | of the The Apache License, Version 2.0, as elucidated in the L<"license | ||
| 138 | file"|https://github.com/iamalnewkirk/zing/blob/master/LICENSE>. | ||
| 139 | |||
| 140 | =head1 PROJECT | ||
| 141 | |||
| 142 | L<Wiki|https://github.com/iamalnewkirk/zing/wiki> | ||
| 143 | |||
| 144 | L<Project|https://github.com/iamalnewkirk/zing> | ||
| 145 | |||
| 146 | L<Initiatives|https://github.com/iamalnewkirk/zing/projects> | ||
| 147 | |||
| 148 | L<Milestones|https://github.com/iamalnewkirk/zing/milestones> | ||
| 149 | |||
| 150 | L<Contributing|https://github.com/iamalnewkirk/zing/blob/master/CONTRIBUTE.md> | ||
| 151 | |||
| 152 | L<Issues|https://github.com/iamalnewkirk/zing/issues> | ||
| 153 | |||
| 154 | =cut |