File Coverage

blib/lib/POE/Component/Server/Bayeux/Message/Factory.pm
Criterion Covered Total %
statement 12 23 52.1
branch 0 6 0.0
condition n/a
subroutine 4 5 80.0
pod 0 1 0.0
total 16 35 45.7


line stmt bran cond sub pod time code
1             package POE::Component::Server::Bayeux::Message::Factory;
2              
3             =head1 NAME
4              
5             POE::Component::Server::Bayeux::Message::Factory - create messages in the right subclass
6              
7             =head1 DESCRIPTION
8              
9             Implements create(), which will find the appropriate Message subclass to handle the data packet.
10              
11             =cut
12              
13 3     3   3078 use strict;
  3         5  
  3         90  
14 3     3   16 use warnings;
  3         4  
  3         105  
15 3         28 use POE qw(
16             Component::Server::Bayeux::Message::Invalid
17             Component::Server::Bayeux::Message::Meta
18             Component::Server::Bayeux::Message::Service
19             Component::Server::Bayeux::Message::Publish
20 3     3   15 );
  3         6  
21              
22 3     3   190 use Params::Validate qw(validate HASHREF ARRAYREF);
  3         7  
  3         736  
23              
24             sub create {
25 0     0 0   my $class = shift;
26              
27 0           my %args = validate(@_, {
28             request => 1,
29             data => { type => HASHREF },
30             });
31              
32 0           my $channel = $args{data}{channel};
33              
34 0           my $build_class;
35 0 0         if (! $channel) {
    0          
    0          
36 0           $build_class = 'Invalid';
37             }
38             elsif ($channel =~ m{^/meta/}) {
39 0           $build_class = 'Meta';
40             }
41             elsif ($channel =~ m{^/service/}) {
42 0           $build_class = 'Service';
43             }
44             else {
45 0           $build_class = 'Publish';
46             }
47              
48 0           $build_class = 'POE::Component::Server::Bayeux::Message::' . $build_class;
49 0           return $build_class->new(%args);
50             }
51              
52             =head1 COPYRIGHT
53              
54             Copyright (c) 2008 Eric Waters and XMission LLC (http://www.xmission.com/).
55             All rights reserved. This program is free software; you can redistribute it
56             and/or modify it under the same terms as Perl itself.
57              
58             The full text of the license can be found in the LICENSE file included with
59             this module.
60              
61             =head1 AUTHOR
62              
63             Eric Waters
64              
65             =cut
66              
67             1;