source: xas/trunk/lib/XAS/Lib/POE/Service.pm @ 356a9c26c4b3ecd30059f983907d4b00a270c27e

Revision 356a9c26c4b3ecd30059f983907d4b00a270c27e, 5.0 KB checked in by Kevin L. Esteb <kevin@…>, 6 years ago (diff)

Fixed some typos

  • Property mode set to 100644
Line 
1package XAS::Lib::POE::Service;
2
3our $VERSION = '0.03';
4
5use POE;
6
7use XAS::Class
8  debug   => 0,
9  version => $VERSION,
10  base    => 'XAS::Lib::POE::Session',
11  vars => {
12    PARAMS => {
13      -alias => { optional => 1, default => 'service' }
14    }
15  }
16;
17
18# ----------------------------------------------------------------------
19# Public Events
20# ----------------------------------------------------------------------
21
22# ----------------------------------------------------------------------
23# Public Methods
24# ----------------------------------------------------------------------
25
26sub session_initialize {
27    my $self = shift;
28
29    my $alias = $self->alias;
30
31    $self->log->debug("$alias: session_initialize()");
32
33    $poe_kernel->state('session_idle',   $self, '_session_idle');
34    $poe_kernel->state('session_pause',  $self, '_session_pause');
35    $poe_kernel->state('session_resume', $self, '_session_resume');
36    $poe_kernel->state('session_status', $self, '_session_status');
37
38    $poe_kernel->sig('HUP', 'session_interrupt');
39
40}
41
42sub session_idle {
43    my $self = shift;
44
45    my $alias = $self->alias;
46
47    $self->log->debug("$alias: session_idle()");
48
49}
50
51sub session_pause {
52    my $self = shift;
53
54    my $alias = $self->alias;
55
56    $self->log->debug("$alias: session_pause()");
57
58}
59
60sub session_resume {
61    my $self = shift;
62
63    my $alias = $self->alias;
64
65    $self->log->debug("$alias: session_resume()");
66
67}
68
69sub session_status {
70    my $self   = shift;
71    my $status = shift;
72
73    my $alias = $self->alias;
74
75    $self->log->debug("$alias: session_status()");
76
77    $self->{'__status'} = $status if (defined($status));
78
79    return $self->{'__status'};
80
81}
82
83# ----------------------------------------------------------------------
84# Public Accessors
85# ----------------------------------------------------------------------
86
87# ----------------------------------------------------------------------
88# Private Methods
89# ----------------------------------------------------------------------
90
91# ----------------------------------------------------------------------
92# Private Events
93# ----------------------------------------------------------------------
94
95sub _session_init {
96    my ($self) = $_[OBJECT];
97
98    my $alias = $self->alias;
99
100    $self->log->debug("$alias: _session_init()");
101
102    $self->session_initialize();
103
104}
105
106sub _session_idle {
107    my ($self) = $_[OBJECT];
108
109    my $alias = $self->alias;
110
111    $self->log->debug("$alias: session_idle()");
112
113    $self->session_idle();
114
115}
116
117sub _session_pause {
118    my ($self) = $_[OBJECT];
119
120    my $alias = $self->alias;
121
122    $self->log->debug("$alias: session_pause()");
123
124    $self->session_pause();
125
126}
127
128sub _session_resume {
129    my ($self) = $_[OBJECT];
130
131    my $alias = $self->alias;
132
133    $self->log->debug("$alias: _session_resume()");
134
135    $self->session_resume();
136
137}
138
139sub _session_status {
140    my ($self, $status) = @_[OBJECT, ARG0];
141
142    my $alias = $self->alias;
143
144    $self->log->debug("$alias: _session_status()");
145
146    $self->session_status($status);
147
148}
149
1501;
151
152__END__
153
154=head1 NAME
155
156XAS::Lib::POE::Service - The base class for all POE Sessions.
157
158=head1 SYNOPSIS
159
160 my $session = XAS::Lib::POE::Session->new(
161     -alias => 'name',
162 );
163
164=head1 DESCRIPTION
165
166This module provides an object based POE session. This object will perform
167the necessary actions for the lifetime of the session. This includes handling
168signals. The following signals INT, TERM, QUIT will trigger the 'shutdown'
169event which invokes the session_cleanup() method. The HUP signal will invoke
170the session_reload() method. This module inherits from XAS::Base.
171
172=head1 METHODS
173
174=head2 session_initialize
175
176This is where the session should do whatever initialization it needs. This
177initialization may include defining additional events.
178
179=head2 session_shutdown
180
181This method should perform cleanup actions for the session. This is triggered
182by a "shutdown" event.
183
184=head2 session_reload
185
186This method should perform reload actions for the session. By default it
187calls $kernel->sig_handled() which terminates further handling of the HUP
188signal.
189
190=head2 session_stop
191
192This method should perform stop actions for the session. This is triggered
193by a "_stop" event.
194
195=head1 PUBLIC EVENTS
196
197The following public events are defined for the session.
198
199=head2 session_startup
200
201This event should start whatever processing the session will do. It is passed
202two parameters:
203
204=head2 session_shutdown
205
206When you send this event to the session, it will invoke the session_cleanup()
207method.
208
209=head1 PRIVATE EVENTS
210
211The following events are used internally:
212
213 session_init
214 session_interrupt
215 session_reload
216 shutdown
217
218They should only be used with caution.
219
220=head1 SEE ALSO
221
222=over 4
223
224=item L<XAS|XAS>
225
226=back
227
228=head1 AUTHOR
229
230Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt>
231
232=head1 COPYRIGHT AND LICENSE
233
234Copyright (C) 2014 Kevin L. Esteb
235
236This library is free software; you can redistribute it and/or modify
237it under the same terms as Perl itself, either Perl version 5.8.8 or,
238at your option, any later version of Perl 5 you may have available.
239
240See L<http://dev.perl.org/licenses/> for more information.
241
242=cut
Note: See TracBrowser for help on using the repository browser.