日向夏特殊応援部隊

俺様向けメモ

Catalystのデプロイに関するあれこれ

雑多なメモです。

とりあえずCatalystにおけるデプロイってどーよって辺りからごニョゴニョしてた内容です。

Module::Install + Module::Install::Catalyst

catalyst.plでgenerateされたMakefile.PLは、

use inc::Module::Install;

name 'MyApp';
all_from 'lib/MyApp.pm';

requires 'Catalyst' => '5.7007';
requires 'Catalyst::Plugin::ConfigLoader';
requires 'Catalyst::Plugin::Static::Simple';
requires 'Catalyst::Action::RenderView';
requires 'YAML'; # This should reflect the config file format you've chosen
                 # See Catalyst::Plugin::ConfigLoader for supported formats
catalyst;

install_script glob('script/*.pl');
auto_install;
WriteAll;

とありますが、ちゃっかりcatalystと言う行があります。
これは実態としてはModule::Install::Catalystcatalystサブルーチンを叩く訳ですが、
実際ソースを読むと、

sub catalyst {
    my $self = shift;
    print <<EOF;
*** Module::Install::Catalyst
EOF
    $self->catalyst_files;
    $self->catalyst_par;
    print <<EOF;
*** Module::Install::Catalyst finished.
EOF
}

のようになってて、catalyst_files, catalyst_parを呼び出してる。
PARが使えるの全然知りませんでしたよ、せんせい。

本筋からそれちゃうけどPAR::Packerがインストールされていれば、

make catalyst_par

でmyapp.parが生成されます。

それは良いとして、いくつか色んな関数が定義されてまして、その中で、

は知っといて損はないかもです。

例えばcatalyst_ignoreだったら、Makefile.PL中で、

catalyst_ignore 'root';
catalyst_files;
catalyst_par;

のようにしておけばrootディレクトリがごっそり除外対象になります。

Catalystのプロジェクトファイルをmake installした際のレイアウト

実際に普通にやってしまうと悲しい思いをするかと思いますので、

perl Makefile.PL DESTDIR=/tmp/build

みたいにしておくのが吉。

結果ですけど、

/Library
/Library/Perl
/Library/Perl/5.8.6
/Library/Perl/5.8.6/darwin-thread-multi-2level
/Library/Perl/5.8.6/darwin-thread-multi-2level/auto
/Library/Perl/5.8.6/darwin-thread-multi-2level/auto/MyApp
/Library/Perl/5.8.6/darwin-thread-multi-2level/auto/MyApp/.packlist
/Library/Perl/5.8.6/MyApp
/Library/Perl/5.8.6/MyApp/Controller
/Library/Perl/5.8.6/MyApp/Controller/Root.pm
/Library/Perl/5.8.6/MyApp/myapp.par
/Library/Perl/5.8.6/MyApp/myapp.yml
/Library/Perl/5.8.6/MyApp/root
/Library/Perl/5.8.6/MyApp/root/favicon.ico
/Library/Perl/5.8.6/MyApp/root/static
/Library/Perl/5.8.6/MyApp/root/static/images
/Library/Perl/5.8.6/MyApp/root/static/images/btn_120x50_built.png
/Library/Perl/5.8.6/MyApp/root/static/images/btn_120x50_built_shadow.png
/Library/Perl/5.8.6/MyApp/root/static/images/btn_120x50_powered.png
/Library/Perl/5.8.6/MyApp/root/static/images/btn_120x50_powered_shadow.png
/Library/Perl/5.8.6/MyApp/root/static/images/btn_88x31_built.png
/Library/Perl/5.8.6/MyApp/root/static/images/btn_88x31_built_shadow.png
/Library/Perl/5.8.6/MyApp/root/static/images/btn_88x31_powered.png
/Library/Perl/5.8.6/MyApp/root/static/images/btn_88x31_powered_shadow.png
/Library/Perl/5.8.6/MyApp/root/static/images/catalyst_logo.png
/Library/Perl/5.8.6/MyApp.pm
/System
/System/Library
/System/Library/Perl
/System/Library/Perl/5.8.6
/System/Library/Perl/5.8.6/darwin-thread-multi-2level
/System/Library/Perl/5.8.6/darwin-thread-multi-2level/perllocal.pod
/usr
/usr/bin
/usr/bin/myapp_cgi.pl
/usr/bin/myapp_create.pl
/usr/bin/myapp_fastcgi.pl
/usr/bin/myapp_server.pl
/usr/bin/myapp_test.pl
/usr/local
/usr/local/man
/usr/local/man/man1
/usr/local/man/man1/myapp_cgi.pl.1
/usr/local/man/man1/myapp_create.pl.1
/usr/local/man/man1/myapp_fastcgi.pl.1
/usr/local/man/man1/myapp_server.pl.1
/usr/local/man/man1/myapp_test.pl.1
/usr/local/man/man3
/usr/local/man/man3/MyApp.3pm
/usr/local/man/man3/MyApp::Controller::Root.3pm

まぁ大体こんな感じになります。ちなみにこれはOSXでの結果です。
HOMEディレクトリが/Library/Perl/5.8.6/MyApp/になってますね。ここが注目だと思います。

HOMEはCatalyst::Utilsのhomeメソッドで判別してますけど、

sub home {
    my $class = shift;

    # make an $INC{ $key } style string from the class name
    (my $file = "$class.pm") =~ s{::}{/}g;

    if ( my $inc_entry = $INC{$file} ) {
        {
            # look for an uninstalled Catalyst app

            # find the @INC entry in which $file was found
            (my $path = $inc_entry) =~ s/$file$//;
            my $home = dir($path)->absolute->cleanup;

            # pop off /lib and /blib if they're there
            $home = $home->parent while $home =~ /b?lib$/;

            # only return the dir if it has a Makefile.PL or Build.PL
            if (-f $home->file("Makefile.PL") or -f $home->file("Build.PL")) {

                # clean up relative path:
                # MyApp/script/.. -> MyApp

                my ($lastdir) = $home->dir_list( -1, 1 );
                if ( $lastdir eq '..' ) {
                    $home = dir($home)->parent->parent;
                }

                return $home->stringify;
            }
        }

        {
            # look for an installed Catalyst app

            # trim the .pm off the thing ( Foo/Bar.pm -> Foo/Bar/ )
            ( my $path = $inc_entry) =~ s/\.pm$//;
            my $home = dir($path)->absolute->cleanup;

            # return if if it's a valid directory
            return $home->stringify if -d $home;
        }
    }

    # we found nothing
    return 0;
}

思い切り丁寧にコメントがあるので分かりますよね。
MyApp/以下にrootなどが突っ込まれる訳です。(まぁ確かに理に適ってますね。)

Catalystもいつの間にやらドキュメントが整備されてきたみたいですねぇ。
ググったら、d.id:nitsuji:20070526:1180155326 が当りました。
僕も一通りCookbookを斜め読みした方がいいなと思いました。