Graduate from .psgi

plackcon #1

Nov 20th, 2013

Profile

songmu

.psgiからの卒業

.psgiファイル

最近のクライアントアプリケーションの流れ

bin/riji

#!/usr/bin/perl
use strict;
use warnings;
use Riji::CLI;
Riji::CLI->run(@ARGV);

scriptにはあまり書かないでテスタブルにする

psgiでも同様

PSGI/Plackアプリケーションの起動方法いろいろと本番環境アレコレ

http://blog.nomadscafe.jp/2013/06/psgiplack.html

例(OrePAN2::Server)

http://www.songmu.jp/riji/entry/2013-10-30-orepan2-inject-psgi.html

use OrePAN2::Injector;
use OrePAN2::Indexer;
use Plack::Request;
use File::Copy qw/move/;
use File::Temp qw/tempdir/;
use File::Spec;

sub {
    my $env = shift;
    my $req = Plack::Request->new($env);

    local $@;
    if ($req->method eq 'POST') {
        eval {
            my $directory = './oreorepanpan';
            my ($module, $author);

            my $tempdir = tempdir( CLEANUP => 1 );
            if (my $upload = $req->upload('pause99_add_uri_httpupload')) {
                $module = File::Spec->catfile($tempdir, $upload->filename);
                move $upload->tempname, $module;
                $author = $req->param('HIDDENNAME');
            }
            else {
                $module = $req->param('module'); # can be a git repo.
                $author = $req->param('author') || 'DUMMY';
            }

            my $injector = OrePAN2::Injector->new(
                directory => $directory,
                author    => $author,
            );
            $injector->inject($module);

            OrePAN2::Indexer->new(directory => $directory)->make_index(
                no_compress => 1,
            );
        };
    }
    if (my $err = $@) {
        [500, [], [$err.'']]
    }
    else {
        [200, [], ['OK']]
    }
};

例(OrePAN2::Server)

after

#!/usr/bin/env perl
use strict;
use warnings;

use OrePAN2::Server::CLI;
OrePAN2::Server::CLI->new(@ARGV)->run;

第1部完

第2部 Puncheur

Puncheur

https://metacpan.org/release/Puncheur

第2部完

第3部 Github::Hooks::Manager

Githubのhook

hookのイベント設定

Github::Hooks::Manager

Making of Github::Hooks::Manager