Giter Site home page Giter Site logo

amon's Introduction

Build Status

NAME

Amon2 - lightweight web application framework

SYNOPSIS

package MyApp;
use parent qw/Amon2/;
use Amon2::Config::Simple;
sub load_config { Amon2::Config::Simple->load(shift) }

DESCRIPTION

Amon2 is simple, readable, extensible, STABLE, FAST web application framework based on Plack.

METHODS

CLASS METHODS for Amon2 class

  • my $c = MyApp->context();

    Get the context object.

  • MyApp->set_context($c)

    Set your context object(INTERNAL USE ONLY).

CLASS METHODS for inherited class

  • MyApp->config()

    This method returns configuration information. It is generated by MyApp->load_config().

  • MyApp->mode_name()

    This is a mode name for Amon2. The default implementation of this method is:

      sub mode_name { $ENV{PLACK_ENV} }
    

    You can override this method if you want to determine the mode by other method.

  • MyApp->new()

    Create new context object.

  • MyApp->bootstrap()

      my $c = MyApp->bootstrap();
    

    Create new context object and set it to global context. When you are writing CLI script, setup the global context object by this method.

  • MyApp->base_dir()

    This method returns the application base directory.

  • MyApp->load_plugin($module_name[, \%config])

    This method loads the plugin for the application.

    $module_name package name of the plugin. You can write it as two form like DBIx::Class:

      __PACKAGE__->load_plugin("Web::CSRFDefender");    # => loads Amon2::Plugin::Web::CSRFDefender
    

    If you want to load a plugin in your own name space, use the '+' character before a package name, like following: __PACKAGE__->load_plugin("+MyApp::Plugin::Foo"); # => loads MyApp::Plugin::Foo

  • MyApp->load_plugins($module_name[, \%config ], ...)

    Load multiple plugins at one time.

    If you want to load a plugin in your own name space, use the '+' character before a package name like following:

      __PACKAGE__->load_plugins("+MyApp::Plugin::Foo"); # => loads MyApp::Plugin::Foo
    
  • MyApp->load_config()

    You can get a configuration hashref from config/$ENV{PLACK_ENV}.pl. You can override this method for customizing configuration loading method.

  • MyApp->add_config()

    DEPRECATED.

  • MyApp->debug_mode()

    ((EXPERIMENTAL))

    This method returns a boolean value. It returns true when $ENV{AMON2_DEBUG} is true value, false otherwise.

    You can override this method if you need.

PROJECT LOCAL MODE

THIS MODE IS HIGHLY EXPERIMENTAL

Normally, Amon2's context is stored in a global variable.

This module makes the context to project local.

It means, normally context class using Amon2 use $Amon2::CONTEXT in each project, but context class using "PROJECT LOCAL MODE" use $MyApp::CONTEXT.

It means you can't use code depend <Amon2-context>> and <Amon2-context>> under this mode.>

NOTES ABOUT create_request

Older Amon2::Web::Request has only 1 argument like following, it uses Amon2->context to get encoding:

sub create_request {
    my ($class, $env) = @_;
    Amon2::Web::Request->new($env);
}

If you want to use "PROJECT LOCAL MODE", you need to pass class name of context class, as following:

sub create_request {
    my ($class, $env) = @_;
    Amon2::Web::Request->new($env, $class);
}

HOW DO I ENABLE PROJECT LOCAL MODE?

MyApp-make_local_context() > turns on the project local mode.

There is no way to revert it, thanks.

METHODS

This module inserts 3 methods to your context class.

  • MyApp->context()

    Shorthand for $MyApp::CONTEXT

  • MyApp->set_context($context)

    It's the same as:

      $MyApp::CONTEXT = $context
    
  • my $guard = MyApp->context_guard()

    Create new context guard class.

    It's the same as:

      Amon2::ContextGuard->new(shift, \$MyApp::CONTEXT);
    

DOCUMENTS

More complicated documents are available on http://amon.64p.org/

SUPPORTS

#amon at irc.perl.org is also available.

AUTHOR

Tokuhiro Matsuno [email protected]

CONTRIBUTORS

  • noblejasper
  • hiratara
  • s-aska
  • Kentaro Kuribayashi
  • Yuki Ibe
  • mattn
  • Masahiro Nagano
  • rightgo09
  • karupanerura
  • hatyuki
  • Keiji, Yoshimi
  • Nishibayashi Takuji
  • dragon3
  • Fuji, Goro
  • issm
  • hisaichi5518
  • Adrian
  • Fuji, Goro
  • ITO Nobuaki
  • Geraud CONTINSOUZAS
  • Syohei YOSHIDA
  • magnolia
  • Katsuhiro Konishi

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

amon's People

Contributors

adriancdperu avatar clicktx avatar dayflower avatar dragon3 avatar gfx avatar hatyuki avatar hiratara avatar hirobanex avatar i110 avatar issm avatar karupanerura avatar kazeburo avatar kentaro avatar konishika avatar mattn avatar moznion avatar neilb avatar noblejasper avatar onopm avatar rightgo09 avatar s-aska avatar sekia avatar syohex avatar takuji31 avatar tokubass avatar tokuhirom avatar walf443 avatar yappo avatar yibe avatar zakame avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

amon's Issues

Windowsでもエラー出ないように

diff --git a/lib/Amon2/Setup/VC/Git.pm b/lib/Amon2/Setup/VC/Git.pm
index 08eb3d1..b1b9284 100644
--- a/lib/Amon2/Setup/VC/Git.pm
+++ b/lib/Amon2/Setup/VC/Git.pm
@@ -18,7 +18,7 @@ sub do_import {

     !system("git init") or die $?;
     !system("git add .") or die $?;
-    !system("git commit -m 'initial import'") or die $?;
+    !system("git commit -m \"initial import\"") or die $?;
 }

 1;

Minilla friendly dist.

Current Amon5's Build.PL is hacked well. It's not minil friendly.
Code move to builder/MyBuilder.pm.

New generated app from 5.06 still needs Router::Simple

Seems that Amon2::Web::Dispatcher::Lite still calls Router::Simple and not Router::Boom:

[zakame@yorozuya:~/src/TmpSpike] master* ± carton exec perl -Ilib script/tmpspike-server
Can't locate Router/Simple.pm in @INC (@INC contains: script/../lib lib /home/zakame
/src/TmpSpike/local/lib/perl5/x86_64-linux /home/zakame/src/TmpSpike/local
/lib/perl5 /home/zakame/perl5/perlbrew/perls/perl-5.14.2/lib/site_perl/5.14.2/x86_64
-linux /home/zakame/perl5/perlbrew/perls/perl-5.14.2/lib/site_perl/5.14.2 /home/zaka
me/perl5/perlbrew/perls/perl-5.14.2/lib/5.14.2/x86_64-linux /home/zakame/perl5/perlb
rew/perls/perl-5.14.2/lib/5.14.2 .) at /home/zakame/src/TmpSpike/local/lib/perl
5/Amon2/Web/Dispatcher/Lite.pm line 5.
BEGIN failed--compilation aborted at /home/zakame/src/TmpSpike/local/lib/perl5/
Amon2/Web/Dispatcher/Lite.pm line 5.
Compilation failed in require at script/../lib/TmpSpike/Web/Dispatcher.pm line 
5.

I know Amon2::Web::Dispatcher::Lite is going to be split off its own dist soon though, so probably its time for the boilerplate in $APP/Web/Dispatcher.pm to be updated? :)

Web::Request->uri_with(): URIエンコードのバグ

uri_with()でURIエンコードがうまくいかないケースがある

原因はよくわかりませんでした

$ amon2-setup.pl MyApp && cd MyApp
$ carton install

### tmpl/index.tt に記述して http://localhost:5000/?q=%E3%81%82 へアクセス(q=あ)
# <a href="[% uri_with() %]">uri_with()</a>: [% uri_with() %]<br>
# <a href="[% uri_with({}) %]">uri_with({})</a>: [% uri_with({}) %]<br>
# <a href="[% uri_with({page => 1}) %]">uri_with({page => 1})</a>: [% uri_with({page => 1}) %]<br>

$ carton exec plackup

# 3つのうち、uri_woth()の出力が違ってるものがある(3つ目のuri_with)

### 開いて何も編集せずに上書き保存
$ vim local/lib/perl5/Amon2/Web/Request.pm

$ carton exec plackup

# なぜか3つの出力が同じになってる!!!

# この後、local/を削除してcarton installし直してもバグは再現しない
# amon2-setup.plからやり直すとバグが再現する

admin.psgi の typo

admin.psgi の 25行目の adin は admin ではないでしょうか?

        root => File::Spec->catdir(dirname(__FILE__), 'static', 'adin');

amon2 シンプルで勉強になります。

5.08+ fails on perl-5.19.4: needs HTTP::Session

Seems like new Amon2 needs an explicit dep on HTTP::Session for the CSRF defender test?

t/600_plugins/008_no_cache.t ................... skipped: Test requires module 'HTTP::Session' but it's not found
Can't locate HTTP/Session/Store/OnMemory.pm in @INC (you may need to install the HTTP::Session::Store::OnMemory module) (@INC contains: /home/zakame/.cpanm/work/1382262323.4252/Amon2-5.09/blib/lib /home/zakame/.cpanm/work/1382262323.4252/Amon2-5.09/blib/arch /home/zakame/.cpanm/work/1382262323.4252/Amon2-5.09/_build/lib /home/zakame/.plenv/versions/5.19.4/lib/perl5/site_perl/5.19.4/x86_64-linux /home/zakame/.plenv/versions/5.19.4/lib/perl5/site_perl/5.19.4 /home/zakame/.plenv/versions/5.19.4/lib/perl5/5.19.4/x86_64-linux /home/zakame/.plenv/versions/5.19.4/lib/perl5/5.19.4 .) at t/600_plugins/009_csrf_defender.t line 35.
BEGIN failed--compilation aborted at t/600_plugins/009_csrf_defender.t line 35.
t/600_plugins/009_csrf_defender.t .............. 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 

Amon2 4.x should depend/recommend Teng

From a freshly-set up Amon2 install and doing amon2-setup.pl HelloFromKoding:

guest-141158@vm-0:~/work/HelloFromKoding$ plackup -r
Watching ./lib app.psgi for file updates.
Error while loading /home/guest-141158/work/HelloFromKoding/app.psgi: Can't locate Teng/Schema/Declare.pm in @INC (you may need to install the Teng
::Schema::Declare module) (@INC contains: /home/guest-141158/work/HelloFromKoding/lib /home/guest-141158/work/HelloFromKoding/extlib/lib/perl5 /hom
e/guest-141158/.plenv/versions/5.18.1/lib/perl5/site_perl/5.18.1/x86_64-linux /home/guest-141158/.plenv/versions/5.18.1/lib/perl5/site_perl/5.18.1 
/home/guest-141158/.plenv/versions/5.18.1/lib/perl5/5.18.1/x86_64-linux /home/guest-141158/.plenv/versions/5.18.1/lib/perl5/5.18.1 .) at /home/gues
t-141158/work/HelloFromKoding/lib/HelloFromKoding/DB/Schema.pm line 6.
BEGIN failed--compilation aborted at /home/guest-141158/work/HelloFromKoding/lib/HelloFromKoding/DB/Schema.pm line 6.
Compilation failed in require at /home/guest-141158/work/HelloFromKoding/lib/HelloFromKoding.pm line 8.
BEGIN failed--compilation aborted at /home/guest-141158/work/HelloFromKoding/lib/HelloFromKoding.pm line 8.
Compilation failed in require at /home/guest-141158/.plenv/versions/5.18.1/lib/perl5/5.18.1/parent.pm line 20.
BEGIN failed--compilation aborted at /home/guest-141158/work/HelloFromKoding/lib/HelloFromKoding/Web.pm line 5.
Compilation failed in require at /home/guest-141158/work/HelloFromKoding/app.psgi line 9.
BEGIN failed--compilation aborted at /home/guest-141158/work/HelloFromKoding/app.psgi line 9.

I know, the new app's cpanfile itself does depend on Teng, but what I mean is that the Amon2 installation should ought to get Teng installed as well (as expected from a new user's perspective.) Or, at the very least, have some blurb at the end of the amon2-setup run for the Basic flavor about installing Teng before further work on the new app.

依存モジュールのご連絡 HTTP::Session::Store::OnMemory

009_csrf_defender.t が HTTP::Session::Store::OnMemory 及び String::Random に依存しているのでテストの際、インストールが必要でした。
String::Random は 002_router_simple.t では Test::Requires に指定されていました。

Use jquery 2.0.x by default.

Older IE was mostly gone. Use jQuery 2.x.x by default.
If user want to support older IEs, users can replace jquery by himself.

is config read only?

https://github.com/tokuhirom/Amon/blob/master/lib/Amon2/Setup/Flavor/Minimum.pm#L148

ここでconfigに書き込みしてしまっている。

MyApp
MyApp::PC -> MyApp
MyApp::Admin -> MyApp
があるときに(Flavor::Largeで作るとこうなりますね)

MyApp->config;
MyApp::PC->config;
MyApp::Admin->config;
の順に呼ぶと

https://github.com/tokuhirom/Amon/blob/master/lib/Amon2.pm#L46
ここでconfigメソッドが定義されてしまう関係上
その三つの->configが返すのは同じreferenceになってしまうので
最初に提示した
view_conf->{path}
が、MyApp::PCとMyApp::Adminで一緒になってしまう。

で、ここはまあ事前に

$view_conf = +{ %{$view_conf} };

としてあげれば解決するわけですが
もし、Amonのポリシーとしてconfigは読み込み専用としないのであればsub configの実装はまずいのかなと思いました!

という、テストケースもつけないバグ報告ですみません><

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.