File Coverage

blib/lib/POE/Component/Client/Bayeux/Transport.pm
Criterion Covered Total %
statement 15 40 37.5
branch 0 6 0.0
condition 0 3 0.0
subroutine 5 17 29.4
pod 0 9 0.0
total 20 75 26.6


line stmt bran cond sub pod time code
1             package POE::Component::Client::Bayeux::Transport;
2              
3 3     3   385511 use strict;
  3         9  
  3         133  
4 3     3   20 use warnings;
  3         7  
  3         103  
5 3     3   18 use Data::Dumper;
  3         6  
  3         242  
6 3     3   18 use Params::Validate;
  3         8  
  3         205  
7 3         23 use POE qw(
8             Component::Client::Bayeux::Transport::LongPolling
9 3     3   19 );
  3         7  
10              
11             my $child_counter = 0;
12              
13             sub spawn {
14 0     0 0   my $class = shift;
15 0           my %args = validate(@_, {
16             type => 1,
17             parent => 1,
18             parent_heap => 1,
19             });
20              
21             # TODO: support more than one transport
22 0 0         die "Support only long-polling at the moment"
23             unless $args{type} eq 'long-polling';
24              
25 0           my $package = 'POE::Component::Client::Bayeux::Transport::LongPolling';
26              
27 0           my @extra_states = $package->extra_states();
28              
29             my $session = POE::Session->create(
30             inline_states => {
31             _start => sub {
32 0     0     my ($kernel, $heap) = @_[KERNEL, HEAP];
33              
34 0           $heap->{alias} = __PACKAGE__ . '_' . $child_counter++;
35 0           $kernel->alias_set($heap->{alias});
36             },
37             _stop => sub {
38 0     0     my ($kernel, $heap) = @_[KERNEL, HEAP];
39 0           $kernel->alias_remove($heap->{alias});
40             },
41             shutdown => sub {
42 0     0     my ($kernel, $heap) = @_[KERNEL, HEAP];
43 0           $kernel->alias_remove($heap->{alias});
44             },
45             },
46 0 0         package_states => [
47             $package => [
48             qw(
49             check startup sendMessages deliver disconnect
50             tunnelCollapse tunnelInit
51             ),
52             @extra_states
53             ],
54             ],
55             heap => {
56             %args,
57             },
58             ($ENV{POE_DEBUG} ? (
59             options => { trace => 1, debug => 1 },
60             ) : ()),
61             );
62              
63 0           return $session->ID;
64             }
65              
66             # Placeholder methods for child transports
67              
68 0     0 0   sub extra_states {
69             }
70 0     0 0   sub check {
71             }
72 0     0 0   sub startup {
73             }
74 0     0 0   sub sendMessages {
75             }
76 0     0 0   sub deliver {
77             }
78 0     0 0   sub disconnect {
79             }
80 0     0 0   sub tunnelCollapse {
81             }
82             sub tunnelInit {
83 0     0 0   my $class = shift;
84 0           my ($kernel, $heap) = @_[KERNEL, HEAP];
85              
86 0 0 0       if (! $heap->{parent_heap}{_initialized} || $heap->{parent_heap}{_connected}) {
87 0           die "Attempting connect() when already connected or not initalized";
88             }
89             }
90              
91             1;