kopug memo

名古屋で働くとあるWebエンジニアの覚書。

mod_perlで同じパッケージ名だけど中身が違うスクリプトを使いたい

これ以前どうやるのか悩んだのでメモっとく。

MyApp というパッケージ名があって、httpd.confはこんな感じだった。

    # Set up your Catalyst app as a mod_perl 2.x application in httpd.conf
    PerlSwitches -I/var/www/MyApp/lib

    # Preload your entire application
    PerlModule MyApp

    <VirtualHost *>
        ServerName    kopug.pugs.jp
        DocumentRoot  /var/www/MyApp/root

        <Location />
            SetHandler          modperl
            PerlResponseHandler MyApp
        </Location>
    </VirtualHost>

この場合 hoge.pugs.jpでも 別ディレクトリにあるMyAppを使いたいって場合、やり方がわからなかった。
でよくよく考えると ModPerl::Registry を使えばいいんじゃないのかって結論に。

    PerlModule ModPerl::Registry
    Alias / /var/www/MyApp/script/myapp_registry.pl/

    <Directory /var/www/MyApp/script>
        Options +ExecCGI
    </Directory>

    <Location />
        SetHandler          perl-script
        PerlResponseHandler ModPerl::Registry
    </Location>


script/myapp_registry.pl

    #!/usr/bin/perl

    use strict;
    use warnings;
    use MyApp;

    MyApp->handle_request( Apache2::RequestUtil->request );

Catalyst::Engine::Apache2::MP20 の PODに書いてあったね。orz