| 1 | package POE::Component::Server::Bayeux::Message::Service; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | POE::Component::Server::Bayeux::Message::Service - handles /service/ channels | ||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | Subclasses L<POE::Component::Server::Bayeux::Message> to implement the /service/* channels. | ||||||||||||||||||||||||||||||||
| 10 | Does nothing by itself, as the Bayeux protocol doesn't define any specific services. Implements named services from the server config 'Services' - see the docs there. | ||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | =cut | ||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
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_accessors(qw(method handler)); | |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 21 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||
| 22 | 0 | my $self = $class->SUPER::new(@_); | |||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | # Extract and save the service method and handler | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 0 | my ($method) = $self->channel =~ m{^/service/(.+)$}; | |||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | if (! $method) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 28 | 0 | $self->request->error("Must provide service method"); | |||||||||||||||||||||||||||||||
| 29 | 0 | return; | |||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||
| 31 | 0 | my $handler = $method; | |||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 0 | my $known_methods = $self->server_config->{Services}; | |||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | # Allow for generic _handler handler | ||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if (! $known_methods->{$method} && $known_methods->{_handler}) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
not $known_methods->{$method} and $known_methods->{"_handler"}
MC/DC0%0/2
not $known_methods->{$method} and $known_methods->{"_handler"}
not $known_methods->{$method}
$known_methods->{"_handler"}
Truth table0%0/3
not(A) and B
A= not $known_methods->{$method}B= $known_methods->{"_handler"}
| |||||||||||||||||||||||||||||||||
| 37 | 0 | $handler = '_handler'; | |||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||
| 39 | elsif (! $known_methods->{$method}) { | ||||||||||||||||||||||||||||||||
| 40 | 0 | $self->request->error("Invalid service method $method"); | |||||||||||||||||||||||||||||||
| 41 | 0 | return; | |||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 0 | $self->method($method); | |||||||||||||||||||||||||||||||
| 45 | 0 | $self->handler($handler); | |||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub handle { | ||||||||||||||||||||||||||||||
|
Subroutine
handle: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 51 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | # Class handle() will call validate_fields() | ||||||||||||||||||||||||||||||||
| 54 | 0 | $self->SUPER::handle(); | |||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 0 | my @responses; | |||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if (! $self->is_error) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 59 | 0 | my $service_definition = $self->server_config->{Services}{ $self->handler }; | |||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if (ref $service_definition && ref $service_definition eq 'CODE') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $service_definition and ref $service_definition eq "CODE"
MC/DC0%0/2
ref $service_definition and ref $service_definition eq "CODE"
ref $service_definition
ref $service_definition eq "CODE"
Truth table0%0/3
A and B
A= ref $service_definitionB= ref $service_definition eq "CODE"
| |||||||||||||||||||||||||||||||||
| 61 | 0 | my @result; | |||||||||||||||||||||||||||||||
| 62 | 0 | eval { | |||||||||||||||||||||||||||||||
| 63 | 0 | @result = $service_definition->($self); | |||||||||||||||||||||||||||||||
| 64 | }; | ||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if (my $ex = $@) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 66 | 0 | my $text; | |||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if (ref($ex) && $ex->can('error')) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $ex and $ex->can("error")
MC/DC0%0/2
ref $ex and $ex->can("error")
ref $ex
$ex->can("error")
Truth table0%0/3
A and B
A= ref $exB= $ex->can("error")
| |||||||||||||||||||||||||||||||||
| 68 | 0 | $text = $ex->error; | |||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||
| 70 | else { | ||||||||||||||||||||||||||||||||
| 71 | 0 | $text = $ex . ''; | |||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||
| 73 | 0 | $self->is_error("Failed to execute method '".$self->handler."' coderef: $text"); | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | push @responses, @result if @result; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if ($self->is_error) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 80 | 0 | push @responses, { | |||||||||||||||||||||||||||||||
| 81 | successful => JSON::XS::false, | ||||||||||||||||||||||||||||||||
| 82 | error => $self->is_error, | ||||||||||||||||||||||||||||||||
| 83 | }; | ||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 0 | foreach my $response (@responses) { | |||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | $response->{channel} ||= $self->channel; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$response->{"channel"} ||= $self->channel
MC/DC0%0/2
$response->{"channel"} ||= $self->channel
$response->{"channel"}
$self->channel
Truth table0%0/3
A ||= B
A= $response->{"channel"}B= $self->channel
| |||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | $response->{id} ||= $self->id if $self->id; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$response->{"id"} ||= $self->id
MC/DC0%0/2
$response->{"id"} ||= $self->id
$response->{"id"}
$self->id
Truth table0%0/3
A ||= B
A= $response->{"id"}B= $self->id
| |||||||||||||||||||||||||||||||||
| 89 | 0 | $self->request->add_response($response); | |||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | Copyright (c) 2008 Eric Waters and XMission LLC (http://www.xmission.com/). | ||||||||||||||||||||||||||||||||
| 96 | All rights reserved. This program is free software; you can redistribute it | ||||||||||||||||||||||||||||||||
| 97 | and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | The full text of the license can be found in the LICENSE file included with | ||||||||||||||||||||||||||||||||
| 100 | this module. | ||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | Eric Waters <ewaters@uarc.com> | ||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | =cut | ||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | 3 | 1; | |||||||||||||||||||||||||||||||