File Coverage

blib/lib/POE/Component/Server/SimpleHTTP/Response.pm
Criterion Covered Total %
statement 24 32 75.0
branch 1 4 25.0
condition 0 2 0.0
subroutine 7 8 87.5
pod 1 2 50.0
total 33 48 68.7


line stmt bran cond sub pod time code
1             package POE::Component::Server::SimpleHTTP::Response;
2              
3 7     7   1639 use strict;
  7         14  
  7         231  
4 7     7   36 use warnings;
  7         11  
  7         474  
5              
6             our $VERSION = '2.20';
7              
8 7     7   37 use base qw( HTTP::Response );
  7         21  
  7         1570  
9              
10 7     7   26975 use Moose;
  7         12  
  7         57  
11             extends qw(HTTP::Response Moose::Object );
12              
13             has '_WHEEL' => (
14             is => 'rw',
15             );
16              
17             has 'connection' => (
18             is => 'ro',
19             writer => 'set_connection',
20             );
21              
22             has 'STREAM_SESSION' => (
23             is => 'rw',
24             );
25              
26             has 'STREAM' => (
27             is => 'rw',
28             );
29              
30             has 'STREAM_DONE' => (
31             is => 'ro',
32             default => sub { 0 },
33             writer => 'set_stream_done',
34             init_arg => undef,
35             );
36              
37             has 'IS_STREAMING' => (
38             is => 'ro',
39             writer => 'set_streaming',
40             );
41              
42             has 'DONT_FLUSH' => (
43             is => 'rw',
44             isa => 'Bool',
45             );
46              
47             sub new {
48 12     12 1 30 my $class = shift;
49              
50             # Get the Wheel ID
51 12         25 my $wid = shift;
52              
53             # Get the Connection object
54 12         30 my $conn = shift;
55              
56             # Make sure we got the wheel ID!
57 12 50       42 if ( !defined $wid ) {
58 0         0 die 'Did not get a Wheel ID!';
59             }
60              
61 12         114 my $self = $class->SUPER::new(@_);
62              
63 12         690 return $class->meta->new_object(
64             __INSTANCE__ => $self,
65             _WHEEL => $wid,
66             connection => $conn,
67             );
68             }
69              
70             sub stream {
71 0     0 0   my $self = shift;
72 0           my %opt = (@_);
73              
74 7     7   47686 no strict 'refs';
  7         16  
  7         771  
75              
76 0 0         if ( $opt{event} ne '' ) {
77 0   0       $self->STREAM_SESSION( $opt{'session'} || undef );
78 0           $self->STREAM( $opt{'event'} );
79 0           $self->DONT_FLUSH( $opt{'dont_flush'} );
80             }
81             else {
82 0           $self->STREAM( shift );
83             }
84             }
85              
86 7     7   41 no Moose;
  7         13  
  7         39  
87              
88             __PACKAGE__->meta->make_immutable( inline_constructor => 0 );
89              
90             # End of module
91             1;
92              
93             __END__
94              
95             =head1 NAME
96              
97             POE::Component::Server::SimpleHTTP::Response - Emulates a HTTP::Response object, used for SimpleHTTP
98              
99             =head1 SYNOPSIS
100              
101             use POE::Component::Server::SimpleHTTP::Response;
102             my $response = POE::Component::Server::SimpleHTTP::Response->new( $wheel_id, $connection );
103              
104             print $response->connection->remote_ip;
105              
106             =head1 DESCRIPTION
107              
108             This module is used as a drop-in replacement, because we need to store the wheel ID + connection object for the response.
109              
110             Use $response->connection to get the SimpleHTTP::Connection object
111              
112             =head2 EXPORT
113              
114             Nothing.
115              
116             =head1 SEE ALSO
117              
118             L<POE::Component::Server::SimpleHTTP>
119              
120             L<POE::Component::Server::SimpleHTTP::Connection>
121              
122             =head1 AUTHOR
123              
124             Apocalypse E<lt>apocal@cpan.orgE<gt>
125              
126             =head1 COPYRIGHT AND LICENSE
127              
128             Copyright 2006 by Apocalypse
129              
130             This library is free software; you can redistribute it and/or modify
131             it under the same terms as Perl itself.
132              
133             =cut