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             $POE::Component::Server::SimpleHTTP::Response::VERSION = '2.26';
3             #ABSTRACT: Emulates a HTTP::Response object, used for SimpleHTTP
4              
5 6     6   29 use strict;
  6         9  
  6         185  
6 6     6   24 use warnings;
  6         8  
  6         274  
7              
8 6     6   27 use base qw( HTTP::Response );
  6         6  
  6         551  
9              
10 6     6   25 use Moose;
  6         8  
  6         40  
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 20 my $class = shift;
49              
50             # Get the Wheel ID
51 12         15 my $wid = shift;
52              
53             # Get the Connection object
54 12         16 my $conn = shift;
55              
56             # Make sure we got the wheel ID!
57 12 50       29 if ( !defined $wid ) {
58 0         0 die 'Did not get a Wheel ID!';
59             }
60              
61 12         82 my $self = $class->SUPER::new(@_);
62              
63 12         491 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 6     6   30714 no strict 'refs';
  6         8  
  6         572  
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 6     6   24 no Moose;
  6         7  
  6         28  
87              
88             __PACKAGE__->meta->make_immutable( inline_constructor => 0 );
89              
90             # End of module
91             1;
92              
93             __END__
94              
95             =pod
96              
97             =encoding UTF-8
98              
99             =head1 NAME
100              
101             POE::Component::Server::SimpleHTTP::Response - Emulates a HTTP::Response object, used for SimpleHTTP
102              
103             =head1 VERSION
104              
105             version 2.26
106              
107             =head1 SYNOPSIS
108              
109             use POE::Component::Server::SimpleHTTP::Response;
110             my $response = POE::Component::Server::SimpleHTTP::Response->new( $wheel_id, $connection );
111              
112             print $response->connection->remote_ip;
113              
114             =head1 DESCRIPTION
115              
116             This module is used as a drop-in replacement, because we need to store the wheel ID + connection object for the response.
117              
118             Use $response->connection to get the SimpleHTTP::Connection object
119              
120             =head2 EXPORT
121              
122             Nothing.
123              
124             =for Pod::Coverage stream
125              
126             =head1 SEE ALSO
127              
128             L<POE::Component::Server::SimpleHTTP>
129              
130             L<POE::Component::Server::SimpleHTTP::Connection>
131              
132             =head1 AUTHOR
133              
134             Apocalypse <APOCAL@cpan.org>
135              
136             =head1 COPYRIGHT AND LICENSE
137              
138             This software is copyright (c) 2017 by Apocalypse, Chris Williams, Eriam Schaffter, Marlon Bailey and Philip Gwyn.
139              
140             This is free software; you can redistribute it and/or modify it under
141             the same terms as the Perl 5 programming language system itself.
142              
143             =cut