| 1 | package Zing::Zang::Watcher; | ||
| 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::ClassHas; | ||
| 13 | |||
| 14 | extends 'Zing::Watcher'; | ||
| 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 'scheme' => ( | ||
| 33 | is => 'ro', | ||
| 34 | isa => 'Scheme', | ||
| 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::Watcher - Watcher Process | ||
| 63 | |||
| 64 | =cut | ||
| 65 | |||
| 66 | =head1 ABSTRACT | ||
| 67 | |||
| 68 | Watcher Process Implementation | ||
| 69 | |||
| 70 | =cut | ||
| 71 | |||
| 72 | =head1 SYNOPSIS | ||
| 73 | |||
| 74 | use Zing::Zang::Watcher; | ||
| 75 | |||
| 76 | my $zang = Zing::Zang::Watcher->new( | ||
| 77 | on_perform => sub { | ||
| 78 | my ($self) = @_; | ||
| 79 | |||
| 80 | $self->{performed}++ | ||
| 81 | }, | ||
| 82 | scheme => ['MyApp', [], 1], | ||
| 83 | ); | ||
| 84 | |||
| 85 | # $zang->execute; | ||
| 86 | |||
| 87 | =cut | ||
| 88 | |||
| 89 | =head1 DESCRIPTION | ||
| 90 | |||
| 91 | This package provides a L<Zing::Watcher> which uses callbacks and doesn't need | ||
| 92 | to be subclassd. It supports providing a process C<perform> method as | ||
| 93 | C<on_perform> and a C<receive> method as C<on_receive> which operate as | ||
| 94 | expected, and also requires a C<scheme> to be launched on execution. | ||
| 95 | |||
| 96 | =cut | ||
| 97 | |||
| 98 | =head1 INHERITS | ||
| 99 | |||
| 100 | This package inherits behaviors from: | ||
| 101 | |||
| 102 | L<Zing::Watcher> | ||
| 103 | |||
| 104 | =cut | ||
| 105 | |||
| 106 | =head1 LIBRARIES | ||
| 107 | |||
| 108 | This package uses type constraints from: | ||
| 109 | |||
| 110 | L<Zing::Types> | ||
| 111 | |||
| 112 | =cut | ||
| 113 | |||
| 114 | =head1 ATTRIBUTES | ||
| 115 | |||
| 116 | This package has the following attributes: | ||
| 117 | |||
| 118 | =cut | ||
| 119 | |||
| 120 | =head2 on_perform | ||
| 121 | |||
| 122 | on_perform(Maybe[CodeRef]) | ||
| 123 | |||
| 124 | This attribute is read-only, accepts C<(Maybe[CodeRef])> values, and is optional. | ||
| 125 | |||
| 126 | =cut | ||
| 127 | |||
| 128 | =head2 on_receive | ||
| 129 | |||
| 130 | on_receive(Maybe[CodeRef]) | ||
| 131 | |||
| 132 | This attribute is read-only, accepts C<(Maybe[CodeRef])> values, and is optional. | ||
| 133 | |||
| 134 | =cut | ||
| 135 | |||
| 136 | =head2 scheme | ||
| 137 | |||
| 138 | scheme(Scheme) | ||
| 139 | |||
| 140 | This attribute is read-only, accepts C<(Scheme)> values, and is required. | ||
| 141 | |||
| 142 | =cut | ||
| 143 | |||
| 144 | =head1 AUTHOR | ||
| 145 | |||
| 146 | Al Newkirk, C<awncorp@cpan.org> | ||
| 147 | |||
| 148 | =head1 LICENSE | ||
| 149 | |||
| 150 | Copyright (C) 2011-2019, Al Newkirk, et al. | ||
| 151 | |||
| 152 | This is free software; you can redistribute it and/or modify it under the terms | ||
| 153 | of the The Apache License, Version 2.0, as elucidated in the L<"license | ||
| 154 | file"|https://github.com/iamalnewkirk/zing/blob/master/LICENSE>. | ||
| 155 | |||
| 156 | =head1 PROJECT | ||
| 157 | |||
| 158 | L<Wiki|https://github.com/iamalnewkirk/zing/wiki> | ||
| 159 | |||
| 160 | L<Project|https://github.com/iamalnewkirk/zing> | ||
| 161 | |||
| 162 | L<Initiatives|https://github.com/iamalnewkirk/zing/projects> | ||
| 163 | |||
| 164 | L<Milestones|https://github.com/iamalnewkirk/zing/milestones> | ||
| 165 | |||
| 166 | L<Contributing|https://github.com/iamalnewkirk/zing/blob/master/CONTRIBUTE.md> | ||
| 167 | |||
| 168 | L<Issues|https://github.com/iamalnewkirk/zing/issues> | ||
| 169 | |||
| 170 | =cut |