lib/POE/Component/MessageQueue/Client.pm

filter: Statementstmt 100% 40 / 40 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 5 totaltotal 87.9% 51 / 58 CC 3 SCAR 4.5
CC
3
Cov
95%
send_frame
3.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.6
« lib/POE/Component/MessageQueue/Storage/DBI.pm ↑ Summary lib/POE/Component/Server/Stomp.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 18 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 18 ▶use POE::Component::MessageQueue::Subscription;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 18 ▶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 12 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
27 18 traits => ['Hash'],
28 handles => {
29 'set_subscription' => 'set',
30 'get_subscription' => 'get',
31 'all_subscriptions' => 'values',
32 'delete_subscription' => 'delete',
33 },
34 );
35  
36 18 has id => (
37 is => 'ro',
38 required => 1,
39 );
40  
41 18 has connected => (
42 is => 'rw',
43 default => 0,
44 );
45  
46 18 has login => (is => 'rw');
47 18 has passcode => (is => 'rw');
48  
49 18 __PACKAGE__->meta->make_immutable();
50  
51 sub subscribe
52 {
53 6 ▶ my ($self, $destination, $client_ack) = @_;
Subroutine subscribe: called CC=1 SCAR=0.0
Pod undocumented
54  
55 6 my $subscription = POE::Component::MessageQueue::Subscription->new(
56 destination => $destination,
57 client => $self,
58 client_ack => $client_ack,
59 );
60  
61 6 $self->set_subscription($destination->name => $subscription);
62 6 $destination->set_subscription($self->id => $subscription);
63 6 return $subscription;
64 }
65  
66 sub unsubscribe
67 {
68 6 ▶ my ($self, $destination) = @_;
Subroutine unsubscribe: called CC=1 SCAR=0.0
Pod undocumented
69  
70 6 $self->delete_subscription($destination->name);
71 6 $destination->delete_subscription($self->id);
72 6 $destination->notify(unsubscribe => {
73 destination => $destination,
74 client => $self,
75 });
76 }
77  
78 sub send_frame
79 {
80 365 ▶ my ($self, $frame) = @_;
Subroutine send_frame: called CC=3 SCAR=11.2
Pod undocumented
81 365 my ($session, $socket);
82  
83 365 ▶ 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 365 365
84 365 ▶ return 0 unless ($socket = $session->get_heap()->{client});
Branch: 1 branch
BranchTrueFalseTotal
unless $socket = $session->get_heap->{"client"} 0 365 365
85  
86 365 $socket->put($frame);
87 365 return 1;
88 }
89  
90 sub connect
91 {
92 11 ▶ my ($self, $login, $passcode) = @_;
Subroutine connect: called CC=1 SCAR=0.0
Pod undocumented
93  
94 11 $self->login($login);
95 11 $self->passcode($passcode);
96 11 $self->connected(1);
97  
98 11 my $id = $self->id;
99 11 $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 11 ▶ my $self = shift;
Subroutine shutdown: called CC=1 SCAR=0.0
Pod undocumented
110 11 $poe_kernel->post($self->id, "shutdown");
111 }
112  
113 18 1;
114  
« lib/POE/Component/MessageQueue/Storage/DBI.pm ↑ Summary lib/POE/Component/Server/Stomp.pm »