lib/POE/Component/MessageQueue/Storage/Remote/Server.pm

filter: Statementstmt 61.2% 19 / 31 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 55.5% 5 / 9 Podpod 0.0% 0 / 1 totaltotal 53.3% 24 / 45 CC 3 SCAR 11.0
CC
3
Cov
54%
__ANON__
6.0
__ANON__
6.0
__ANON__
2.0
CRAP 3.0
« lib/POE/Component/MessageQueue/Storage/FileSystem.pm ↑ Summary lib/POE/Component/MessageQueue/Storage/Remote.pm »
1 #
2 # Copyright 2008 Paul Driver <frodwith@gmail.com>
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
17  
18 package POE::Component::MessageQueue::Storage::Remote::Server;
19 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use POE::Filter::Reference;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use POE::Component::Server::TCP;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use POE::Component::MessageQueue::Storage::BigMemory;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 2 has session_id => (
26 is => 'rw',
27 isa => 'Int',
28 init_arg => undef,
29 );
30  
31 has storage => (
32 is => 'ro',
33 does => 'POE::Component::MessageQueue::Storage',
34 0 ▶ default => sub { POE::Component::MessageQueue::Storage::BigMemory->new },
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 2 );
36  
37 2 has port => (
38 is => 'ro',
39 isa => 'Int',
40 required => 1,
41 );
42  
43 sub BUILD
44 {
45 0 ▶ my ($self, $args) = @_;
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod undocumented
46  
47 $self->session_id(POE::Component::Server::TCP->new(
48 Port => $self->port,
49 ClientFilter => POE::Filter::Reference->new,
50  
51 ClientInput => sub {
52 0 ▶ my ($heap, $request) = @_[HEAP, ARG0];
Subroutine __ANON__: not called CC=2 SCAR=17.9
53 0 my ($method, $args) = @{$request}{'method', 'args'};
54 0 my $callback_id = pop(@$args);
55 0 my $storage = $self->storage;
56  
57 0 ▶ if (my $method_ref = $storage->can($method))
Branch: 1 branch
BranchTrueFalseTotal
if (my $method_ref = $storage->can($method)) 0 0 0
58 {
59 $method_ref->($storage, @$args, sub {
60 $heap->{client}->put({
61 0 ▶ callback => $callback_id,
Subroutine __ANON__: not called CC=2 SCAR=17.9
62 args => [@_]
63 });
64 0 ▶ $poe_kernel->post($self->session_id, 'shutdown')
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "storage_shutdown" 0 0 0
65 if ($method eq 'storage_shutdown');
66 0 });
67 }
68 },
69 0 ));
70 }
71  
72 2 1;
73  
74 =pod
75  
76 =head1 NAME
77  
78 POE::Component::MessageQueue::Storage::Remote::Server -- Expose a storage
79 engine as a service over a TCP socket
80  
81 =head1 DESCRIPTION
82  
83 This module wraps any storage engine and exposes it as a service over a TCP
84 socket. It handles multiple clients. It takes requests in the form of a
85 Storable hashref of the form C<< { 'method_name' => [arg1, arg2, etc] } >>.
86  
87 =head1 CONSTRUCTOR PARAMETERS
88  
89 =over 2
90  
91 =item port
92  
93 The port number to listen on.
94  
95 =item storage
96  
97 A L<POE::Component::MessageQUeue::Storage> engine to wrap.
98  
99 =back
100  
101 =head1 SEE ALSO
102  
103 L<POE::Component::MessageQueue::Storage::Remote>
104  
105 =cut
106  
« lib/POE/Component/MessageQueue/Storage/FileSystem.pm ↑ Summary lib/POE/Component/MessageQueue/Storage/Remote.pm »