Server/Bayeux/Message/Publish.pm

filter: Statementstmt 42.4% 14 / 33 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 4 / 8 Podpod 50.0% 2 / 4 totaltotal 32.2% 20 / 62 CC 9 SCAR 23.5
CC
9
Cov
29%
handle
20.0
handle_error
12.0
add_response
12.0
CRAP 10.5
« Client/Bayeux/Transport/LongPolling.pm ↑ Summary Server/Bayeux/Message/Factory.pm »
1 package POE::Component::Server::Bayeux::Message::Publish;
2  
3 =head1 NAME
4  
5 POE::Component::Server::Bayeux::Message::Publish - handles non-special channels
6  
7 =head1 DESCRIPTION
8  
9 Subclasses L<POE::Component::Server::Bayeux::Message> to implement the non-special channels. This will usually mean a publish to a channel, so a successfuly handled message will simply be passed to the server via $request->publish(), with a response given back to the requesting client.
10  
11 =cut
12  
13 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use JSON::Any qw(XS);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use base qw(POE::Component::Server::Bayeux::Message);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 3 __PACKAGE__->mk_data_accessors(qw(data));
19  
20 0 ▶sub validate_fields {
Subroutine validate_fields: not called CC=2 SCAR=17.9
Pod documented
21 0 my ($self) = @_;
22  
23 $self->SUPER::validate_fields(
24 data => 1,
25  
26 # Optional to require clientId on publish
27 ($self->server_config->{AnonPublish} ?
28 0 ▶ () : (
Branch: 1 branch
BranchTrueFalseTotal
$self->server_config->{'AnonPublish'} ? : 0 0 0
29 clientId => 1,
30 )),
31 );
32 }
33  
34 0 ▶sub handle {
Subroutine handle: not called CC=4 SCAR=30.0
Pod documented
35 0 my ($self) = @_;
36  
37 # Class handle() will call validate_fields()
38 0 $self->SUPER::handle();
39 0 ▶ return $self->handle_error() if $self->is_error();
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_error 0 0 0
40  
41 # Perform client acl (if client provided)
42 0 my $client;
43 0 ▶ if ($self->clientId) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->clientId) 0 0 0
44 0 $client = $self->request->client($self->clientId);
45 0 $client->message_acl($self);
46 0 ▶ return $self->handle_error() if $self->is_error();
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_error 0 0 0
47 }
48  
49 0 $self->request->publish($self->clientId, $self->channel, $self->data);
50  
51 # Optional to respond to a publish
52 0 $self->add_response({
53 successful => JSON::XS::true,
54 });
55 }
56  
57 0 ▶sub handle_error {
Subroutine handle_error: not called CC=3 SCAR=24.8
Pod undocumented
58 0 my ($self, $error) = @_;
59  
60 0 ▶ my %response = (
Condition0%0/5
$error || $self->is_error || ''
l!l
00
$error or $self->is_error
l!l&&r!l&&!r
000
MC/DC0%0/2
$error || $self->is_error || ''
$error $self->is_error
Truth table0%0/3
A or B
A= $errorB= $self->is_error
ABresult
1X1
011
000
61 successful => JSON::XS::false,
62 error => $error || $self->is_error || '',
63 );
64  
65 0 return $self->add_response(\%response);
66 }
67  
68 0 ▶sub add_response {
Subroutine add_response: not called CC=3 SCAR=24.8
Pod undocumented
69 0 my ($self, $response) = @_;
70  
71 0 foreach my $key (qw(channel clientId id)) {
72 0 ▶ $response->{$key} = $self->$key if defined $self->$key;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->$key 0 0 0
73 }
74  
75 0 $self->request->add_response($response);
76 }
77  
78 =head1 COPYRIGHT
79  
80 Copyright (c) 2008 Eric Waters and XMission LLC (http://www.xmission.com/).
81 All rights reserved. This program is free software; you can redistribute it
82 and/or modify it under the same terms as Perl itself.
83  
84 The full text of the license can be found in the LICENSE file included with
85 this module.
86  
87 =head1 AUTHOR
88  
89 Eric Waters <ewaters@uarc.com>
90  
91 =cut
92
93 3 1;
« Client/Bayeux/Transport/LongPolling.pm ↑ Summary Server/Bayeux/Message/Factory.pm »