こんにちは,五十嵐です.今回は Catalyst を使った開発環境を作成します.Catalyst を使用するためには,Perl の CPAN モジュールを利用して,Task::Catalyst をインストールする必要があります.
Perl の環境にインストールできる権限を持ったユーザでの作業になります.一般にはスーパーユーザー(root) で作業を行うとよいでしょう.CPAN のインストール方法にはコマンドラインから直接 perl で呼び出す方法と,cpan コマンドを利用する方法があります.
# perl -MCPAN -e 'install Task::Catalyst'# cpan
cpan[1]> install Task::Catalyst
cpan[2]> quit
どちらの方法でも構いませんが,私は cpan コマンドの方を好んで使っています.いずれの場合でも,初めて CPAN を使用する場合には,いくつかの質問に答える必要があります.ここでは詳細は記述しませんが,興味のある方は 「perl の catalyst - Catalyst を使ってみる #000」 (2007/01/11)をご覧ください(ただし,詳細なログはログインユーザのみに公開しています).
Task::Catalyst のモジュールをインストールすると,catalyst.pl というコマンドが使用できるようになります./usr/bin/catalyst.pl にインストールされますので,一般ユーザで使用できます.このコマンドは,Catalyst の開発環境を作成してくれます.引数にアプリケーション名を指定します.指定したアプリケーション名がそのままディレクトリ名になって環境が作成されます.ただし,ハイフン('-') をアプリケーション名に含めると,動いてくれないようです."Secure-SBM" からハイフンを取り除いて,"SecureSBM" をアプリケーション名とします.
$ catalyst.pl SecureSBM
created "SecureSBM"
(出力省略)
created "SecureSBM/script/securesbm_create.pl"
$ ls -l
合計 4
drwxrwxr-x 6 ikarashi ikarashi 4096 3月 19 19:52 SecureSBM
$ $ cd SecureSBM
$ ./script/securesbm_server.pl
[debug] Debug messages enabled
[warn] You are running an old script!
Please update by running (this will overwrite existing files):
catalyst.pl -force -scripts SecureSBM
or (this will not overwrite existing files):
catalyst.pl -scripts SecureSBM
[debug] Loaded plugins:
.----------------------------------------------------------------------------.
| Catalyst::Plugin::Static::Simple 0.15 |
'----------------------------------------------------------------------------'
[debug] Loaded dispatcher "Catalyst::Dispatcher"
[debug] Loaded engine "Catalyst::Engine::HTTP"
[debug] Found home "....(省略)/SecureSBM"
[debug] Loaded Private actions:
.----------------------+--------------------------------------+--------------.
| Private | Class | Method |
+----------------------+--------------------------------------+--------------+
| /default | SecureSBM | default |
'----------------------+--------------------------------------+--------------'
[info] SecureSBM powered by Catalyst 5.7007
You can connect to your server at http://sarek.gatacon.jp:3000
実行直後に表示されるメッセージ:
[warn] You are running an old script!は気になりますが,"catalyst.pl -force -script SecureSBM" とやってみても変わらないので,様子見としましょう.catalyst.pl との整合性が取れていないのかもしれませんが,cpan で upgrade しているので,これ以上バージョンがあがりません.(事あるごとに "catalyst.pl -force -scripts SecureSBM" を試しているのですが...)
さて,"./script/securesbm_server.pl" を実行しただけで,port 3000 で簡単なウェブサーバが動いているのと同じことになります.catalyst.pl で作成したディレクトリ=環境のなかのファイルを参照して実行しています.ブラウザで "http://localhost:3000/" にアクセスすると,Catalyst の初期画面が表示されます.
バージョンの整合性が取れていないのか,以前は自動的に作られていたlib/SecureSBM/Controller/Root.pm が作成されないので,以下のような Root.pm を作成しました.
package SecureSBM::Controller::Root;
use strict;
use warnings;
use base 'Catalyst::Controller';
#
# Sets the actions in this controller to be registered with no prefix
# so they function identically to actions created in MyApp.pm
#
__PACKAGE__->config->{namespace} = '';
=head1 NAME
SecureSBM::Controller::Root - Root Controller for SecureSBM
=head1 DESCRIPTION
[enter your description here]
=head1 METHODS
=cut
#=head2 end
#
#Attempt to render a view, if needed.
#
#=cut
#
#sub end : ActionClass('RenderView') {
# my ( $self, $c ) = @_;
#}
=head1 AUTHOR
Satoshi Ikarashi
=head1 LICENSE
This Program is distributed under version 1.0 of the Rinza Public
License Agreement, that is bundled with this package in the file
LICENSE, and is available through the website at the following URL:
http://www.tyzoh.jp/rinza/licenses/LICENSE-1.0.txt.
This is the Original Program.
The Initial Developer of the Original Program is Nihon Unisys, Ltd.
The Original Program is copyrighted (C) 2006-2007 by Nihon Unisys, Ltd. with
all rights reserved.
There is NO WARRANTY OF ANY KIND by the Initial Developer of the
Original Program.
=cut
1;という環境になっています.前述の通り,それぞれのモジュールを "perl -MCPAN -e 'install ModuleName" か "cpan" コマンドを起動して "install ModuleName" でインストールしておきます.初期の段階はこれらで十分でしょう.今後必要になった時点で,追加していきます.
最後にCatalyst::Manual::Tutorial::CatalystBasics - Catalyst Tutorial - Part 2: Catalyst Application Development Basicsに従って,Catalyst::Plugin::ConfigLoader と Catalyst::Plugin::StackTrace を使えるようにしておきます.lib/SecureSBM.pm ファイルを以下のように変更します.
Index: SecureSBM.pm
===================================================================
--- SecureSBM.pm
+++ SecureSBM.pm
@@ -9,8 +9,14 @@
# -Debug: activates the debug mode for very useful log messages
# Static::Simple: will serve static files from the applications root
directory
#
-use Catalyst qw/-Debug Static::Simple/;
+use Catalyst qw/
+ -Debug
+ ConfigLoader
+ Static::Simple
+ StackTrace
+ /;
+
our $VERSION = '0.01';
#タグ:Secure-SBM
いかちょー (2007-04-25 16:39) | コメント(0)| トラックバック(48)
トラックバックURL:
月別アーカイブ
Copyright (C) 2004-2011 Nihon Unisys, Ltd. All Rights Reserved.
Powered by Movable Type Open Source