| 1 | package POEx::Role::PSGIServer::ProxyWriter; | ||
| 2 | BEGIN { | ||
| 3 | $POEx::Role::PSGIServer::ProxyWriter::VERSION = '1.110670'; | ||
| 4 | } | ||
| 5 | |||
| 6 | #ABSTRACT: Provides a push writer for PSGI applications to use | ||
| 7 | use MooseX::Declare; | ||
| 8 | |||
| 9 | class POEx::Role::PSGIServer::ProxyWriter { | ||
| 10 | use MooseX::Types::Moose(':all'); | ||
| 11 | use POEx::Types::PSGIServer(':all'); | ||
| 12 | |||
| 13 | |||
| 14 | has server_context => ( | ||
| 15 | is => 'ro', | ||
| 16 | isa => PSGIServerContext, | ||
| 17 | required => 1 | ||
| 18 | ); | ||
| 19 | |||
| 20 | |||
| 21 | has proxied => ( | ||
| 22 | is => 'ro', | ||
| 23 | isa => Object, | ||
| 24 | weak_ref => 1, | ||
| 25 | required => 1, | ||
| 26 | ); | ||
| 27 | |||
| 28 | |||
| 29 | method write($data) { | ||
| 30 | $self->proxied->write($self->server_context, $data); | ||
| 31 | } | ||
| 32 | |||
| 33 | |||
| 34 | method close() { | ||
| 35 | $self->proxied->close($self->server_context); | ||
| 36 | } | ||
| 37 | |||
| 38 | |||
| 39 | method poll_cb(CodeRef $coderef) { | ||
| 40 | my $on_flush = sub { $self->$coderef() }; | ||
| 41 | my $id = $self->server_context->{wheel}->ID; | ||
| 42 | $self->proxied->set_wheel_flusher($id => $on_flush); | ||
| 43 | $on_flush->(); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | 1; | ||
| 47 | |||
| 48 | |||
| 49 | =pod | ||
| 50 | |||
| 51 | =head1 NAME | ||
| 52 | |||
| 53 | POEx::Role::PSGIServer::ProxyWriter - Provides a push writer for PSGI applications to use | ||
| 54 | |||
| 55 | =head1 VERSION | ||
| 56 | |||
| 57 | version 1.110670 | ||
| 58 | |||
| 59 | =head1 PUBLIC_ATTRIBUTES | ||
| 60 | |||
| 61 | =head2 server_context | ||
| 62 | |||
| 63 | is: ro, isa: PSGIServerContext, required: 1 | ||
| 64 | |||
| 65 | This is the server context from POEx::Role::PSGIServer. It is needed to determine the semantics of the current request | ||
| 66 | |||
| 67 | =head2 proxied | ||
| 68 | |||
| 69 | is: ro, isa: Object, weak_ref: 1, required: 1 | ||
| 70 | |||
| 71 | This is the actual object that consumes POEx::Role::PSGIServer. It is weakened to make sure it is properly collected when the connection closes | ||
| 72 | |||
| 73 | =head1 PUBLIC_METHODS | ||
| 74 | |||
| 75 | =head2 write | ||
| 76 | |||
| 77 | ($data) | ||
| 78 | |||
| 79 | write proxies to the weakened PSGIServer consumer object passing along the L</server_context> | ||
| 80 | |||
| 81 | =head2 close | ||
| 82 | |||
| 83 | close is proxied to the weakened PSGIServer consumer passing along L</server_context> | ||
| 84 | |||
| 85 | =head2 poll_cb | ||
| 86 | |||
| 87 | (CodeRef $coderef) | ||
| 88 | |||
| 89 | poll_cb is provided to complete the interface. The first argument to $coderef will be $self | ||
| 90 | |||
| 91 | =head1 AUTHOR | ||
| 92 | |||
| 93 | Nicholas Perez <nperez@cpan.org> | ||
| 94 | |||
| 95 | =head1 COPYRIGHT AND LICENSE | ||
| 96 | |||
| 97 | This software is copyright (c) 2011 by Infinity Interactive. | ||
| 98 | |||
| 99 | This is free software; you can redistribute it and/or modify it under | ||
| 100 | the same terms as the Perl 5 programming language system itself. | ||
| 101 | |||
| 102 | =cut | ||
| 103 | |||
| 104 | |||
| 105 | __END__ |