lib/POE/Component/MessageQueue/Client.pm

filter: Statementstmt 77.5% 31 / 40 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 5 totaltotal 68.9% 40 / 58 CC 3 SCAR 5.6
CC
3
Cov
75%
send_frame
3.1
subscribe
2.0
unsubscribe
2.0
CRAP 1.7
« lib/POE/Component/MessageQueue/Storage.pm ↑ Summary lib/POE/Component/MessageQueue/IDGenerator/UUID.pm »
1  
2 # Copyright 2007-2010 David Snopek <dsnopek@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::Client;
19 13 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 13 ▶use POE::Component::MessageQueue::Subscription;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 13 ▶use POE::Kernel;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 has subscriptions => (
24 is => 'ro',
25 isa => 'HashRef[POE::Component::MessageQueue::Subscription]',
26 2 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
27 13 traits => ['Hash'],
28 handles => {
29 'set_subscription' => 'set',
30 'get_subscription' => 'get',
31 'all_subscriptions' => 'values',
32 'delete_subscription' => 'delete',
33 },
34 );
35  
36 13 has id => (
37 is => 'ro',
38 required => 1,
39 );
40  
41 13 has connected => (
42 is => 'rw',
43 default => 0,
44 );
45  
46 13 has login => (is => 'rw');
47 13 has passcode => (is => 'rw');
48  
49 13 __PACKAGE__->meta->make_immutable();
50  
51 sub subscribe
52 {
53 0 ▶ my ($self, $destination, $client_ack) = @_;
Subroutine subscribe: not called CC=1 SCAR=6.9
Pod undocumented
54  
55 0 my $subscription = POE::Component::MessageQueue::Subscription->new(
56 destination => $destination,
57 client => $self,
58 client_ack => $client_ack,
59 );
60  
61 0 $self->set_subscription($destination->name => $subscription);
62 0 $destination->set_subscription($self->id => $subscription);
63 0 return $subscription;
64 }
65  
66 sub unsubscribe
67 {
68 0 ▶ my ($self, $destination) = @_;
Subroutine unsubscribe: not called CC=1 SCAR=6.9
Pod undocumented
69  
70 0 $self->delete_subscription($destination->name);
71 0 $destination->delete_subscription($self->id);
72 0 $destination->notify(unsubscribe => {
73 destination => $destination,
74 client => $self,
75 });
76 }
77  
78 sub send_frame
79 {
80 2 ▶ my ($self, $frame) = @_;
Subroutine send_frame: called CC=3 SCAR=11.2
Pod undocumented
81 2 my ($session, $socket);
82  
83 2 ▶ return 0 unless ($session = $poe_kernel->alias_resolve($self->id));
Branch: 1 branch
BranchTrueFalseTotal
unless $session = $POE::Component::MessageQueue::Client::poe_kernel->alias_resolve($self->id) 0 2 2
84 2 ▶ return 0 unless ($socket = $session->get_heap()->{client});
Branch: 1 branch
BranchTrueFalseTotal
unless $socket = $session->get_heap->{"client"} 0 2 2
85  
86 2 $socket->put($frame);
87 2 return 1;
88 }
89  
90 sub connect
91 {
92 1 ▶ my ($self, $login, $passcode) = @_;
Subroutine connect: called CC=1 SCAR=0.0
Pod undocumented
93  
94 1 $self->login($login);
95 1 $self->passcode($passcode);
96 1 $self->connected(1);
97  
98 1 my $id = $self->id;
99 1 $self->send_frame(Net::Stomp::Frame->new({
100 command => "CONNECTED",
101 headers => {
102 session => "client-$id",
103 },
104 }));
105 }
106  
107 sub shutdown
108 {
109 1 ▶ my $self = shift;
Subroutine shutdown: called CC=1 SCAR=0.0
Pod undocumented
110 1 $poe_kernel->post($self->id, "shutdown");
111 }
112  
113 13 1;
114  
« lib/POE/Component/MessageQueue/Storage.pm ↑ Summary lib/POE/Component/MessageQueue/IDGenerator/UUID.pm »