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

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

Fixing some bugs and updating some documentation

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