読者です 読者をやめる 読者になる 読者になる

m_shige1979のささやかな抵抗と欲望の日々

プログラムの勉強をしながら学習したことや経験したことをぼそぼそと書いていきます

なんとなく作ったサイト

http://www.it-check-matome.info/


Github(注意すること)

https://github.com/mshige1979

Amon2のフレームワークを触ってみる

別に

Mojoliciousに飽きたわけではない。他のフレームワークにも触れておく必要があると感じだけ

インストール

cpanm Amon2

フレームワークなので入れるものが非常に多い

なんかamon2-setup.pl が使用できるようになったみたい

$ amon2-setup.pl 
Usage:
        % amon2-setup.pl MyApp

            --flavor=Basic      basic flavour (default)
            --flavor=Lite       Amon2::Lite flavour (need to install)
            --flavor=Minimum    minimalistic flavour for benchmarking
            --flavor=Standalone CPAN uploadable web application(EXPERIMENTAL)

            --vc=Git         setup the git repository (default)

            --list-flavors (or -l) Shows the list of flavors installed

            --help   Show this help

$

最初はベーシックで作成

$ amon2-setup.pl MyApp1 --flavor=Basic
-- Running flavor: Basic --
[main] Loading asset: jQuery
[main] Loading asset: Bootstrap
[main] Loading asset: ES5Shim
[main] Loading asset: MicroTemplateJS
[main] Loading asset: StrftimeJS
[main] Loading asset: SprintfJS
[main] Loading asset: MicroLocationJS
[main] Loading asset: MicroDispatcherJS
[main] Loading asset: XSRFTokenJS
[Flavor::Basic] writing tmpl/index.tx
[Flavor::Basic] writing tmpl/include/layout.tx
[Flavor::Basic] writing tmpl/include/pager.tx
[Flavor::Basic] writing lib/MyApp1.pm
[Flavor::Basic] writing lib/MyApp1/Web.pm
[Flavor::Basic] writing lib/MyApp1/Web/Plugin/Session.pm
[Flavor::Basic] writing lib/MyApp1/Web/Dispatcher.pm
[Flavor::Basic] writing lib/MyApp1/Web/View.pm
[Flavor::Basic] writing lib/MyApp1/Web/ViewFunctions.pm
[Flavor::Basic] writing lib/MyApp1/DB.pm
[Flavor::Basic] writing lib/MyApp1/DB/Schema.pm
[Flavor::Basic] writing lib/MyApp1/DB/Row.pm
[Flavor::Basic] writing script/myapp1-server
[Flavor::Basic] writing Build.PL
[Flavor::Basic] writing minil.toml
[Flavor::Basic] writing builder/MyBuilder.pm
[Flavor::Basic] writing cpanfile
[Flavor::Basic] writing static//js/jquery-2.1.1.min.js
[Flavor::Basic] writing static//bootstrap/fonts/glyphicons-halflings-regular.ttf
[Flavor::Basic] writing static//bootstrap/css/bootstrap-theme.css.map
[Flavor::Basic] writing static//bootstrap/css/bootstrap-theme.min.css
[Flavor::Basic] writing static//bootstrap/js/bootstrap.js
[Flavor::Basic] writing static//bootstrap/fonts/glyphicons-halflings-regular.woff
[Flavor::Basic] writing static//bootstrap/js/bootstrap.min.js
[Flavor::Basic] writing static//bootstrap/css/bootstrap-theme.css
[Flavor::Basic] writing static//bootstrap/css/bootstrap.min.css
[Flavor::Basic] writing static//bootstrap/fonts/glyphicons-halflings-regular.svg
[Flavor::Basic] writing static//bootstrap/css/bootstrap.css
[Flavor::Basic] writing static//bootstrap/fonts/glyphicons-halflings-regular.eot
[Flavor::Basic] writing static//bootstrap/css/bootstrap.css.map
[Flavor::Basic] writing static//js/es5-shim.min.js
[Flavor::Basic] writing static//js/micro_template.js
[Flavor::Basic] writing static//js/strftime.js
[Flavor::Basic] writing static//js/sprintf.js
[Flavor::Basic] writing static//js/micro-location.js
[Flavor::Basic] writing static//js/micro_dispatcher.js
[Flavor::Basic] writing static//js/xsrf-token.js
[Flavor::Basic] writing static/img/.gitignore
[Flavor::Basic] writing static/robots.txt
[Flavor::Basic] writing static/js/main.js
[Flavor::Basic] writing static/css/main.css
[Flavor::Basic] writing db/.gitignore
[Flavor::Basic] writing config/development.pl
[Flavor::Basic] writing config/production.pl
[Flavor::Basic] writing config/test.pl
[Flavor::Basic] writing sql/mysql.sql
[Flavor::Basic] writing sql/sqlite.sql
[Flavor::Basic] writing t/Util.pm
[Flavor::Basic] writing t/00_compile.t
[Flavor::Basic] writing t/01_root.t
[Flavor::Basic] writing t/02_mech.t
[Flavor::Basic] writing t/03_assets.t
[Flavor::Basic] writing t/06_jshint.t
[Flavor::Basic] writing xt/01_pod.t
[Flavor::Basic] writing xt/02_perlcritic.t
[Flavor::Basic] writing .gitignore
[Flavor::Basic] writing .proverc
[Flavor::Basic] writing static/500.html
[Flavor::Basic] writing static/503.html
[Flavor::Basic] writing static/502.html
[Flavor::Basic] writing static/504.html
[Flavor::Basic] writing static/404.html
Initialized empty Git repository in /vagrant/perl/amon2/MyApp1/.git/
[master (root-commit) b0548a1] initial import
 62 files changed, 10636 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 .proverc
 create mode 100644 Build.PL
 create mode 100644 builder/MyBuilder.pm
 create mode 100644 config/development.pl
 create mode 100644 config/production.pl
 create mode 100644 config/test.pl
 create mode 100644 cpanfile
 create mode 100644 db/.gitignore
 create mode 100644 lib/MyApp1.pm
 create mode 100644 lib/MyApp1/DB.pm
 create mode 100644 lib/MyApp1/DB/Row.pm
 create mode 100644 lib/MyApp1/DB/Schema.pm
 create mode 100644 lib/MyApp1/Web.pm
 create mode 100644 lib/MyApp1/Web/Dispatcher.pm
 create mode 100644 lib/MyApp1/Web/Plugin/Session.pm
 create mode 100644 lib/MyApp1/Web/View.pm
 create mode 100644 lib/MyApp1/Web/ViewFunctions.pm
 create mode 100644 minil.toml
 create mode 100644 script/myapp1-server
 create mode 100644 sql/mysql.sql
 create mode 100644 sql/sqlite.sql
 create mode 100644 static/404.html
 create mode 100644 static/500.html
 create mode 100644 static/502.html
 create mode 100644 static/503.html
 create mode 100644 static/504.html
 create mode 100644 static/bootstrap/css/bootstrap-theme.css
 create mode 100644 static/bootstrap/css/bootstrap-theme.css.map
 create mode 100644 static/bootstrap/css/bootstrap-theme.min.css
 create mode 100644 static/bootstrap/css/bootstrap.css
 create mode 100644 static/bootstrap/css/bootstrap.css.map
 create mode 100644 static/bootstrap/css/bootstrap.min.css
 create mode 100644 static/bootstrap/fonts/glyphicons-halflings-regular.eot
 create mode 100644 static/bootstrap/fonts/glyphicons-halflings-regular.svg
 create mode 100644 static/bootstrap/fonts/glyphicons-halflings-regular.ttf
 create mode 100644 static/bootstrap/fonts/glyphicons-halflings-regular.woff
 create mode 100644 static/bootstrap/js/bootstrap.js
 create mode 100644 static/bootstrap/js/bootstrap.min.js
 create mode 100644 static/css/main.css
 create mode 100644 static/img/.gitignore
 create mode 100644 static/js/es5-shim.min.js
 create mode 100644 static/js/jquery-2.1.1.min.js
 create mode 100644 static/js/main.js
 create mode 100644 static/js/micro-location.js
 create mode 100644 static/js/micro_dispatcher.js
 create mode 100644 static/js/micro_template.js
 create mode 100644 static/js/sprintf.js
 create mode 100644 static/js/strftime.js
 create mode 100644 static/js/xsrf-token.js
 create mode 100644 static/robots.txt
 create mode 100644 t/00_compile.t
 create mode 100644 t/01_root.t
 create mode 100644 t/02_mech.t
 create mode 100644 t/03_assets.t
 create mode 100644 t/06_jshint.t
 create mode 100644 t/Util.pm
 create mode 100644 tmpl/include/layout.tx
 create mode 100644 tmpl/include/pager.tx
 create mode 100644 tmpl/index.tx
 create mode 100644 xt/01_pod.t
 create mode 100644 xt/02_perlcritic.t
--------------------------------------------------------------

Setup script was done! You are ready to run the skelton.

You need to install the dependencies by:

    > carton install

And then, run your application server:

    > carton exec perl -Ilib script/myapp1-server

--------------------------------------------------------------
$
不足するモジュールをインストール
cd MyApp1/
carton install
起動
$ carton exec perl -Ilib script/myapp1-server
MyApp1: http://127.0.0.1:5000/


f:id:m_shige1979:20141211002846p:plain
※起動しない?

IPが異なるからプライベートIP指定したけどダメらしい
のでIPを変更する

script/myapp1-server
#!perl
use strict;
use warnings;
use utf8;
use File::Spec;
use File::Basename;
use lib File::Spec->catdir(dirname(__FILE__), '../lib');
use Plack::Builder;

use MyApp1::Web;
use MyApp1;
use URI::Escape;
use File::Path ();

my $app = builder {
    enable 'Plack::Middleware::Static',
        path => qr{^(?:/static/)},
        root => File::Spec->catdir(dirname(__FILE__), '..');
    enable 'Plack::Middleware::Static',
        path => qr{^(?:/robots\.txt|/favicon\.ico)$},
        root => File::Spec->catdir(dirname(__FILE__), '..', 'static');
    enable 'Plack::Middleware::ReverseProxy';

    MyApp1::Web->to_app();
};
unless (caller) {
    my $port        = 5000;
    # my $host        = '127.0.0.1';
    my $host        = '192.168.33.10';
    my $max_workers = 4;

    require Getopt::Long;
    require Plack::Loader;
    my $p = Getopt::Long::Parser->new(
        config => [qw(posix_default no_ignore_case auto_help)]
    );
    $p->getoptions(
        'p|port=i'      => \$port,
        'host=s'        => \$host,
        'max-workers=i' => \$max_workers,
        'version!'      => \my $version,
        'c|config=s'    => \my $config_file,
    );
    if ($version) {
        print "MyApp1: $MyApp1::VERSION\n";
        exit 0;
    }
    if ($config_file) {
        my $config = do $config_file;
        Carp::croak("$config_file: $@") if $@;
        Carp::croak("$config_file: $!") unless defined $config;
        unless ( ref($config) eq 'HASH' ) {
            Carp::croak("$config_file does not return HashRef.");
        }
        no warnings 'redefine';
        no warnings 'once';
        *MyApp1::load_config = sub { $config }
    }

    print "MyApp1: http://${host}:${port}/\n";

    my $loader = Plack::Loader->load('Starlet',
        port        => $port,
        host        => $host,
        max_workers => $max_workers,
    );
    return $loader->run($app);
}
return $app;

再度起動

$ carton exec perl -Ilib script/myapp1-server 
MyApp1: http://192.168.33.10:5000/


f:id:m_shige1979:20141211003218p:plain

ちゃんとでた
出ないからちょっと焦りました(^_^;)

所感

今回はセットアップまで他にもフレームワークはあるけどとりあえずこれを触ってみる。
perlの勉強会にいくとよく聞くフレームワークなのでちょっといろいろ調べて見よう

広告を非表示にする