Amon2

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN


4.02 2013-09-17T03:12:00Z

    - Add Amon2::Web->create_simple_status_page().
      (daylflower)
    - Recommend to install Teng.
      (Suggested by zakame)

4.01 2013-08-22T03:23:21Z

    - Fixed utf8 flag issue in uri_with().
      Before this version, if the key was flagged, it makes MOJIBAKE.
      https://github.com/tokuhirom/Amon/issues/63
      (Reported by ichigotake++)

4.00 2013-08-21T03:44:49Z

    - Bump to 4.00!
      (tokuhirom)

3.99_01 2013-08-20T04:59:03Z

Changes  view on Meta::CPAN


    [FEATURE ENHANCEMENT]
    - Setup::VC::Git: initialize git repository automatically by default

3.09 2011-10-16

    [FEATURE ENHANCEMENT]
    - set "X-Frame-Options: DENY" by default

    [3.08 not released]
    - Bug fix: Flavor: Added 'use utf8' to some of *.pm .

3.07 2011-10-14

    [BUG FIX]
    - fixed testing issue

3.06 2011-10-13

    [BUG FIX]
    - fixed dependencies

author/assets.pl  view on Meta::CPAN

#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use 5.008001;
use lib 'lib';
use LWP::UserAgent;
use autodie;
use Data::Dumper;
use File::Basename;
use File::Temp qw/tmpnam tempdir/;
use Text::Xslate;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );

author/assets.pl  view on Meta::CPAN

                     .split("\t").join("');")
                     .split("%>").join("p.push('")
                     + "');}return p.join('');");

        // Provide some basic currying to the user
        return data ? fn( data ) : fn;
    };
})();
...

    open my $fh, '>:utf8', 'lib/Amon2/Setup/Asset/MicroTemplateJS.pm';
    print {$fh} $xslate->render_string(<<'...', +{ file => $0, basename => 'micro_template.js', data => Dumper({ 'js/micro_template.js' => $content})});
# This file is generated by <% file %>. Do not edit manually.
package Amon2::Setup::Asset::MicroTemplateJS;
use strict;
use warnings;

sub tags {
    <<',,,';
    <script src="<: uri_for('/static/js/<% basename %>') :>"></script>
,,,

author/assets.pl  view on Meta::CPAN

    my ($class, $method, $url, $name) = @_;

    no strict 'refs';
    *{__PACKAGE__ . '::' . $method} = sub {
        use strict;

        my $res = $ua->get($url);
        $res->is_success or die "Cannot fetch $url: " . $res->status_line;

        my $content = $res->decoded_content;
        open my $fh, '>:utf8', "lib/Amon2/Setup/Asset/${name}.pm";
        print {$fh} $xslate->render_string(<<'...', +{ file => $0, basename => basename($url), name => $name, data => Dumper({ 'js/' . basename($url) => $content})});
# This file is generated by <% file %>. Do not edit manually.
package Amon2::Setup::Asset::<% name %>;
use strict;
use warnings;

sub tags {
    <<',,,';
    <script src="<: uri_for('/static/js/<% basename %>') :>"></script>
,,,

author/assets.pl  view on Meta::CPAN

        close $fh;
    };
}

sub run_jquery {
    my $url = 'http://code.jquery.com/jquery-3.6.1.min.js';
    my $res = $ua->get($url);
    $res->is_success or die "Cannot fetch $url: " . $res->status_line;

    my $jquery = $res->decoded_content;
    open my $fh, '>:utf8', 'lib/Amon2/Setup/Asset/jQuery.pm';
    print {$fh} $xslate->render_string(<<'...', +{ file => $0, basename => basename($url), data => Dumper({ 'js/' . basename($url) => $jquery})});
# This file is generated by <% file %>. Do not edit manually.
package Amon2::Setup::Asset::jQuery;
use strict;
use warnings;

sub tags {
    <<',,,';
    <script src="<: uri_for('/static/js/<% basename %>') :>"></script>
,,,

author/assets.pl  view on Meta::CPAN

    my $files = $class->files;
    $flavor->mkpath('static/bootstrap/');
    while (my ($fname, $content) = each %$files) {
        $flavor->write_file_raw("static/$fname", uri_unescape($content));
    }
}

1;
...

    open my $fh, '>:utf8', 'lib/Amon2/Setup/Asset/Bootstrap.pm';
    print {$fh} $content;
    close $fh;

    eval "use Amon2::Setup::Asset::Bootstrap;";
    die $@ if $@;
}

eg/LongPoll/chat.psgi  view on Meta::CPAN

use strict;
use warnings;
use utf8;
use Amon2::Lite;
use Digest::MD5 ();
use Tatsumaki::MessageQueue;
use Amon2::Web::Response::Callback;

get '/' => sub {
    my $c = shift;
    return $c->render('index.tt');
};

eg/realtime-chat/chat.psgi  view on Meta::CPAN

use strict;
use warnings;
use utf8;
use Amon2::Lite;
use Digest::MD5 ();

print "PID: $$\n";

get '/' => sub {
    my $c = shift;
    return $c->render('index.tt');
};

lib/Amon2/ContextGuard.pm  view on Meta::CPAN

package Amon2::ContextGuard;
# THIS IS INTERNAL CLASS.
# DO NOT USE THIS CLASS DIRECTLY.
use strict;
use warnings;
use utf8;

sub new {
    my ($class, $context, $dst) = @_;
    my $orig = $$dst;
    $$dst = $context;
    bless [$orig, $dst], $class;
}

sub DESTROY {
    my $self = shift;

lib/Amon2/Plugin/Web/PlackSession.pm  view on Meta::CPAN

use strict;
use warnings;
use utf8;

package Amon2::Plugin::Web::PlackSession;
use Plack::Session;

sub init {
    my ($class, $context_class, $conf) = @_;

    no strict 'refs';
    *{"${context_class}::session"} = sub {
        Plack::Session->new($_[0]->request->env)

lib/Amon2/Plugin/Web/Streaming.pm  view on Meta::CPAN

package Amon2::Plugin::Web::Streaming;
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);
}

lib/Amon2/Plugin/Web/WebSocket.pm  view on Meta::CPAN

package Amon2::Plugin::Web::WebSocket;
use strict;
use warnings;
use utf8;

use Amon2::Util;

use AnyEvent::Handle;
use Amon2::Web::WebSocket;
use Amon2::Web::Response::Callback;
use Protocol::WebSocket 0.00906;
use Protocol::WebSocket::Frame;
use Protocol::WebSocket::Handshake::Server;

lib/Amon2/Setup/Flavor.pm  view on Meta::CPAN

use strict;
use warnings;
use utf8;

package Amon2::Setup::Flavor;
use Text::Xslate;
use File::Spec;
use File::Basename;
use File::Path ();
use Amon2;
use Plack::Util ();
use Carp ();
use Amon2::Trigger;

lib/Amon2/Setup/Flavor/Basic.pm  view on Meta::CPAN

use strict;
use warnings FATAL => 'all';
use utf8;

package Amon2::Setup::Flavor::Basic;
use parent qw(Amon2::Setup::Flavor);

our $VERSION = '6.16';

sub run {
    my $self = shift;

    # write code.

lib/Amon2/Setup/Flavor/Large.pm  view on Meta::CPAN

use strict;
use warnings FATAL => 'all';
use utf8;

package Amon2::Setup::Flavor::Large;
use parent qw(Amon2::Setup::Flavor);
use File::Path ();

our $VERSION = '6.16';

sub admin_script {
    my $self = shift;
    my $admin_script = 'script/' . lc($self->{dist}) . '-admin-server';

lib/Amon2/Setup/Flavor/Minimum.pm  view on Meta::CPAN

package Amon2::Setup::Flavor::Minimum;
use strict;
use warnings FATAL => 'all';
use utf8;
use parent qw(Amon2::Setup::Flavor);

our $VERSION = '6.16';

sub run {
    my ($self) = @_;

    $self->render_file('lib/<<PATH>>.pm',                   'Minimum/lib/__PATH__.pm');
    $self->render_file("tmpl/index.tx",                     'Minimum/tmpl/index.tx');
    $self->render_file($self->psgi_file,                    'Minimum/script/server.pl');

lib/Amon2/Setup/VC/Git.pm  view on Meta::CPAN

package Amon2::Setup::VC::Git;
use strict;
use warnings;
use utf8;
use File::Temp qw(tempfile);

sub new {
    bless {}, $_[0];
}

sub do_import {
    my ($self) = @_;

    unless ($self->_is_git_available('git')) {

lib/Amon2/Web/Dispatcher/RouterBoom.pm  view on Meta::CPAN

package Amon2::Web::Dispatcher::RouterBoom;
use strict;
use warnings;
use utf8;
use 5.008_001;
use Router::Boom::Method;

sub import {
    my $class = shift;
    my %args = @_;
    my $caller = caller(0);

    my $router = Router::Boom::Method->new();

lib/Amon2/Web/Request.pm  view on Meta::CPAN

    my $append = 0;
    if((ref($behavior) eq 'HASH') && defined($behavior->{mode}) && ($behavior->{mode} eq 'append')) {
        $append = 1;
    }

    my $params = do {
        foreach my $value ( values %$args ) {
            next unless defined $value;
            for ( ref $value eq 'ARRAY' ? @$value : $value ) {
                $_ = "$_";
                utf8::encode($_) if utf8::is_utf8($_);
            }
        }

        my %params = %{ $self->uri->query_form_hash };
        foreach my $key ( keys %{$args} ) {
            my $val = $args->{$key};
            if (utf8::is_utf8($key)) {
                $key = Encode::encode($self->_encoding(), $key);
            }
            if ( defined($val) ) {

                if ( $append && exists( $params{$key} ) ) {

                  # This little bit of heaven handles appending a new value onto
                  # an existing one regardless if the existing value is an array
                  # or not, and regardless if the new value is an array or not
                    $params{$key} = [

lib/Amon2/Web/Response/Callback.pm  view on Meta::CPAN

package Amon2::Web::Response::Callback;
use strict;
use warnings;
use utf8;
use Carp ();
use HTTP::Headers ();

sub new {
    my $class = shift;
    my %args = @_ == 1 ? %{$_[0]} : @_;
    $args{code} || Carp::croak "Missing mandatory parameter: code";
    bless {
        headers => HTTP::Headers->new,
        %args

lib/Amon2/Web/WebSocket.pm  view on Meta::CPAN

package Amon2::Web::WebSocket;
use strict;
use warnings;
use utf8;

sub new {
    my $class = shift;
    my %args = @_==1 ? %{$_[0]} : @_;
    bless {
        %args
    }, $class;
}

sub on_receive_message {

share/flavor/Basic/lib/__PATH__.pm  view on Meta::CPAN

package <% $module %>;
use strict;
use warnings;
use utf8;
our $VERSION='0.01';
use 5.008001;
use <% $module %>::DB::Schema;
use <% $module %>::DB;

use parent qw/Amon2/;
# Enable project local mode.
__PACKAGE__->make_local_context();

my $schema = <% $module %>::DB::Schema->instance;

share/flavor/Basic/lib/__PATH__/DB.pm  view on Meta::CPAN

package <% $module %>::DB;
use strict;
use warnings;
use utf8;
use parent qw(Teng);

__PACKAGE__->load_plugin('Count');
__PACKAGE__->load_plugin('Replace');
__PACKAGE__->load_plugin('Pager');

1;

share/flavor/Basic/lib/__PATH__/DB/Row.pm  view on Meta::CPAN

package <% $module %>::DB::Row;
use strict;
use warnings;
use utf8;
use parent qw(Teng::Row);

1;

share/flavor/Basic/lib/__PATH__/DB/Schema.pm  view on Meta::CPAN

package <% $module %>::DB::Schema;
use strict;
use warnings;
use utf8;

use Teng::Schema::Declare;

base_row_class '<% $module %>::DB::Row';

table {
    name 'member';
    pk 'id';
    columns qw(id name);
};

share/flavor/Basic/lib/__PATH__/Web.pm  view on Meta::CPAN

package <% $module %>::Web;
use strict;
use warnings;
use utf8;
use parent qw/<% $module %> Amon2::Web/;
use File::Spec;

# dispatcher
use <% $module %>::Web::Dispatcher;
sub dispatch {
    return (<% $module %>::Web::Dispatcher->dispatch($_[0]) or die "response is not generated");
}

# load plugins

share/flavor/Basic/lib/__PATH__/Web/Dispatcher.pm  view on Meta::CPAN

package <% $module %>::Web::Dispatcher;
use strict;
use warnings;
use utf8;
use Amon2::Web::Dispatcher::RouterBoom;

any '/' => sub {
    my ($c) = @_;
    my $counter = $c->session->get('counter') || 0;
    $counter++;
    $c->session->set('counter' => $counter);
    return $c->render('index.tx', {
        counter => $counter,
    });

share/flavor/Basic/lib/__PATH__/Web/Plugin/Session.pm  view on Meta::CPAN

package <% $package // ($module ~ "::Web::Plugin::Session") %>;
use strict;
use warnings;
use utf8;

use Amon2::Util;
use HTTP::Session2::ClientStore2;
use Crypt::CBC;

sub init {
    my ($class, $c) = @_;

    # Validate XSRF Token.
    $c->add_trigger(

share/flavor/Basic/t/03_assets.t  view on Meta::CPAN

use strict;
use warnings;
use utf8;
use t::Util;
use Plack::Test;
use Plack::Util;
use Test::More;

my $app = Plack::Util::load_psgi '<% $psgi_file // "app.psgi" %>';
test_psgi
    app => $app,
    client => sub {
        my $cb = shift;

share/flavor/Large/lib/__PATH__/Web/C/Account.pm  view on Meta::CPAN

package <% $module %>::Web::C::Account;
use strict;
use warnings;
use utf8;

sub logout {
    my ($class, $c) = @_;
    $c->session->expire();
    $c->redirect('/');
}

1;

share/flavor/Large/lib/__PATH__/__MONIKER__.pm  view on Meta::CPAN

package <% $module %>::<% $moniker %>;
use strict;
use warnings;
use utf8;
use parent qw(<% $module %> Amon2::Web);
use File::Spec;

# dispatcher
use <% $module %>::<% $moniker %>::Dispatcher;
sub dispatch {
    return (<% $module %>::<% $moniker %>::Dispatcher->dispatch($_[0]) or die "response is not generated");
}

# setup view

share/flavor/Large/lib/__PATH__/__MONIKER__/C/Root.pm  view on Meta::CPAN

package <% $module %>::<% $moniker %>::C::Root;
use strict;
use warnings;
use utf8;

sub index {
    my ($class, $c) = @_;

    my $counter = $c->session->get('counter') || 0;
    $counter++;
    $c->session->set('counter' => $counter);
    return $c->render('index.tx', {
        counter => $counter,
    });

share/flavor/Large/lib/__PATH__/__MONIKER__/Dispatcher.pm  view on Meta::CPAN

package <% $module %>::<% $moniker %>::Dispatcher;
use strict;
use warnings;
use utf8;
use Amon2::Web::Dispatcher::RouterBoom;
use Module::Find qw(useall);

# Load all controller classes at loading time.
useall('<% $module %>::<% $moniker %>::C');

base '<% $module %>::<% $moniker %>::C';

get '/' => 'Root#index';
post '/reset_counter' => 'Root#reset_counter';

share/flavor/Large/lib/__PATH__/__MONIKER__/ViewFunctions.pm  view on Meta::CPAN

package <% $module %>::<% $moniker %>::ViewFunctions;
use strict;
use warnings;
use utf8;
use parent qw(Exporter);
use Module::Functions;
use File::Spec;

our @EXPORT = get_public_functions();

sub commify {
    local $_  = shift;
    1 while s/((?:\A|[^.0-9])[-+]?\d+)(\d{3})/$1,$2/s;
    return $_;



( run in 1.623 second using v1.01-cache-2.11-cpan-49f99fa48dc )