Server/Bayeux/Message/Service.pm

filter: Statementstmt 22.9% 11 / 48 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 60.0% 3 / 5 Podpod 100% 2 / 2 totaltotal 16.0% 16 / 100 CC 17 SCAR 47.9
CC
17
Cov
13%
handle
182.0
new
30.0
BEGIN
1.0
CRAP 120.0
« Server/Bayeux/Request.pm ↑ Summary Server/Bayeux/Client.pm »
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
BranchTrueFalseTotal
unless ($method) 0 0 0
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
BranchTrueFalseTotal
if (not $known_methods->{$method} and $known_methods->{'_handler'}) { } 0 0 0
elsif (not $known_methods->{$method}) { } 0 0 0
Condition0%0/3
not $known_methods->{$method} and $known_methods->{"_handler"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless ($self->is_error) 0 0 0
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
BranchTrueFalseTotal
if (ref $service_definition and ref $service_definition eq "CODE") 0 0 0
Condition0%0/3
ref $service_definition and ref $service_definition eq "CODE"
!ll&&!rl&&r
000
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"
ABresult
0X0
100
111
61 0 my @result;
62 0 eval {
63 0 @result = $service_definition->($self);
64 };
65 0 ▶ if (my $ex = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ex = $@) 0 0 0
66 0 my $text;
67 0 ▶ if (ref($ex) && $ex->can('error')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ex and $ex->can('error')) { } 0 0 0
Condition0%0/3
ref $ex and $ex->can("error")
!ll&&!rl&&r
000
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")
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if @result 0 0 0
76 }
77 }
78  
79 0 ▶ if ($self->is_error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_error) 0 0 0
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
l!l&&r!l&&!r
000
MC/DC0%0/2
$response->{"channel"} ||= $self->channel
$response->{"channel"} $self->channel
Truth table0%0/3
A ||= B
A= $response->{"channel"}B= $self->channel
ABresult
1X1
011
000
88 0 ▶ $response->{id} ||= $self->id if $self->id;
Branch: 1 branch
BranchTrueFalseTotal
if $self->id 0 0 0
Condition0%0/3
$response->{"id"} ||= $self->id
l!l&&r!l&&!r
000
MC/DC0%0/2
$response->{"id"} ||= $self->id
$response->{"id"} $self->id
Truth table0%0/3
A ||= B
A= $response->{"id"}B= $self->id
ABresult
1X1
011
000
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;
« Server/Bayeux/Request.pm ↑ Summary Server/Bayeux/Client.pm »