Amon2
    
    
  
  
  
view release on metacpan or search on metacpan
    - fixed testing issue
      (karupanerura)
    - added micro-location.js
3.52 2012-08-09
    - upgrade jQuery 1.7.2 to 1.8.0
3.51 2012-08-08
    - streaming support
3.50 2012-08-06
    - websocket support
3.39 2012-08-05
    - Bundled es5shim.js, sprintf.js, strftime.js, micro_template.js
3.38 2012-08-01
t/300_setup/08_installable.t
t/300_setup/09_minil_migrate.t
t/600_plugins/005_fillin_form_lite.t
t/600_plugins/007_json.t
t/600_plugins/007_json_default_encoding.t
t/600_plugins/007_json_hijacking.t
t/600_plugins/007_json_keysort.t
t/600_plugins/007_json_x_api_status.t
t/600_plugins/008_no_cache.t
t/600_plugins/010_plack_session.t
t/600_plugins/012_streaming.t
t/600_plugins/013_websocket.t
t/600_plugins/014_streaming_header_splitting.t
t/800_dispatcher/002_router_simple.t
t/800_dispatcher/003_lite.t
t/800_dispatcher/004_router_boom.t
t/800_dispatcher/004_router_boom_sinatraish.t
t/TestFlavor.pm
t/Util.pm
t/tmpl/foo.mt
xt/02_perlcritic.t
xt/06_dependencies.t
xt/skelton/01_basic.t
eg/LongPoll/chat.psgi view on Meta::CPAN
        }
    );
    return $c->render_json({ok => 1});
};
any '/poll' => sub {
    my ($c) = @_;
    my $client_id = $c->req->param('client_id')
        or die;
    return $c->streaming_json(sub {
        my $writer = shift;
        $mq->poll_once($client_id, sub {
            $writer->write_json(\@_);
            $writer->close;
        });
    });
};
# load plugins
lib/Amon2/Plugin/Web/Streaming.pm view on Meta::CPAN
use strict;
use warnings;
use utf8;
use Amon2::Util;
use Amon2::Web::Response::Callback;
sub init {
    my ($class, $c, $conf) = @_;
    Amon2::Util::add_method(ref $c || $c, 'streaming', \&_streaming);
    Amon2::Util::add_method(ref $c || $c, 'streaming_json', \&_streaming_json);
}
sub _streaming {
    my ($self, $code) = @_;
    
    return Amon2::Web::Response::Callback->new(
        code => sub {
            $code->(@_);
        }
    );
}
sub _streaming_json {
    my ($self, $code) = @_;
    return Amon2::Web::Response::Callback->new(
        code => sub {
            my $respond = shift;
            my $writer = $respond->([200, ['Content-Type' => 'application/json;charset=utf-8']]);
            my $longpoll_ctx = Amon2::Plugin::Web::Streaming::Writer->new(
                $self,
                $writer
lib/Amon2/Plugin/Web/Streaming.pm view on Meta::CPAN
sub close {
    my ($self) = @_;
    $self->{writer}->close();
}
1;
__END__
=head1 NAME
Amon2::Plugin::Web::Streaming - streaming support for Amon2
=head1 SYNOPSIS
    use Amon2::Lite;
    __PACKAGE__->load_plugin(qw/Web::Streaming/);
    any '/poll' => sub {
        my $c = shift;
        return $c->streaming(sub {
            my $respond = shift;
            ...;
            $respond->write([200, [], ['OK']]);
        });
    };
    any '/poll_json' => sub {
        my $c = shift;
        return $c->streaming_json(sub {
            my $writer = shift;
            ...;
            $writer->write_json(+{ });
            $writer->close;
        });
    };
=head1 DESCRIPTION
This is an Amon2 plugin to support streaming.
You MUST use the HTTP server supporting psgi.streaming.
=head1 EXPORTED METHODS
=over 4
=item $c->streaming($code);
You can return delayed response for PSGI spec.
Argument for $code is C<< $respond >>. It's same as a argument for PSGI callback.
=item $c->streaming_json($code);
It's a short hand utility to publish streaming JSON.
The argument is instance of Amon2::Plugin::Web::Streaming::Writer.
=back
=head1 Amon2::Plugin::Streaming::Writer METHODS
=over 4
=item new
lib/Amon2/Web/Response/Callback.pm view on Meta::CPAN
        Amon2::Web::Response::Callback->new(
            code => sub {
                my $respond = shift;
                $respond->([200, [], []]);
            }
        );
    };
=head1 DESCRIPTION
This module provides a response object for delayed response/streaming body.
You can embed the AE support, streaming support, etc on Amon2 with this module.
=head1 SEE ALSO
L<Tatsumaki>
t/600_plugins/012_streaming.t view on Meta::CPAN
$Plack::Test::Impl = "Server";
use Amon2;
{
    package MyApp::Web;
    use parent -norequire, qw/MyApp/;
    use parent qw/Amon2::Web/;
    sub dispatch {
        my $c = shift;
        $c->streaming(sub {
            my ($respond) = @_;
            my $writer = $respond->(
                [200, ['Content-Type', 'text/html']]);
            $writer->write("<html>\n");
            for my $i (1..5) {
                $writer->write("<div>$i</div>\n");
            }
            $writer->write("</html>\n");
            $writer->close;
        });
t/600_plugins/014_streaming_header_splitting.t view on Meta::CPAN
$Plack::Test::Impl = "Server";
use Amon2;
{
    package MyApp::Web;
    use parent -norequire, qw/MyApp/;
    use parent qw/Amon2::Web/;
    sub dispatch {
        my $c = shift;
        $c->streaming(sub {
            my ($respond) = @_;
            my $writer = $respond->(
                [200, ['Content-Type', "text/html\015\012hogehoge"]]);
            $writer->write("<html>\n");
            for my $i (1..5) {
                $writer->write("<div>$i</div>\n");
            }
            $writer->write("</html>\n");
            $writer->close;
        });
( run in 0.473 second using v1.01-cache-2.11-cpan-c333fce770f )