« lib/auto/share/dist/App-SocialCalc-Multiplayer/third-party/lib/PocketIO/Resource.pm
↑ Summary
lib/auto/share/dist/App-SocialCalc-Multiplayer/third-party/lib/PocketIO/Handle.pm »
| 1 | package PocketIO; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use base 'Plack::Component'; | ||
| 7 | |||
| 8 | our $VERSION = '0.00904'; | ||
| 9 | |||
| 10 | use Plack::Util (); | ||
| 11 | use Plack::Util::Accessor qw(resource handler class instance method); | ||
| 12 | |||
| 13 | use PocketIO::Resource; | ||
| 14 | |||
| 15 | sub new { | ||
| 16 | my $self = shift->SUPER::new(@_); | ||
| 17 | |||
| 18 | $self->handler($self->_get_handler); | ||
| 19 | |||
| 20 | return $self; | ||
| 21 | } | ||
| 22 | |||
| 23 | sub call { | ||
| 24 | my $self = shift; | ||
| 25 | my ($env) = @_; | ||
| 26 | |||
| 27 | return PocketIO::Resource->dispatch($env, $self->handler) | ||
| 28 | || [400, ['Content-Type' => 'text/plain'], ['Bad request']]; | ||
| 29 | } | ||
| 30 | |||
| 31 | sub _get_handler { | ||
| 32 | my $self = shift; | ||
| 33 | |||
| 34 | return $self->handler if $self->handler; | ||
| 35 | |||
| 36 | die q{Either 'handler', 'class' or 'instance' must be specified} | ||
| 37 | unless $self->instance || $self->class; | ||
| 38 | |||
| 39 | my $method = $self->method || 'run'; | ||
| 40 | |||
| 41 | my $instance = $self->instance | ||
| 42 | || do { Plack::Util::load_class($self->class); $self->class->new; }; | ||
| 43 | |||
| 44 | return $instance->run; | ||
| 45 | } | ||
| 46 | |||
| 47 | 1; | ||
| 48 | __END__ |