| 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
| |||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||
| 41 | # Perform client acl (if client provided) | ||||||||||||||||||||||||
| 42 | 0 | my $client; | |||||||||||||||||||||||
| 43 | 0 | ▶ | if ($self->clientId) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||
| 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 || ''
$error or $self->is_error
MC/DC0%0/2
$error || $self->is_error || ''
$error
$self->is_error
Truth table0%0/3
A or B
A= $errorB= $self->is_error
| |||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||