昨日はスケルトン作成までやった。
今日の目標は動かすところまでやる。
富田さんのを参考に進めてみる。
MVCのうち、viewをまず作成する。
作成したディレクトリへ移動。
ここで行き詰まる。
つまり、まだ入ってないみたいなのでCPANでインスコ。
よし、無事に入ったようなので改めてview作成。
これでview作成完了。
次にMVCのうち、Cのコントローラ部分のMyApp.pmを編集。
コントローラ部分はMyApp/lib/MyApp.pmの部分。
MyApp.pmの中身。
まず、どのように動くのか確認するために内容を下記のコードにかえる。
コントローラ部分の動きは後で学ぶ。
次にMVCのモデル、ページを作成。
作成場所はMyApp/root/でpage2.htmlを作成。
これで下準備は完了。
実際に動かしてみる。
サーバー立ち上げ完了。
http://makotoworld.dyndns.org:3000にアクセスし動いているか、確認。
無事に動いてます。
次にモデルで作成したpage2のチェック。
http://makotoworld.dyndns.org:3000/page2にアクセス。
これも無事に動いてまする。
今度はコントローラの使い方を調べてみる。
今日の目標は動かすところまでやる。
富田さんのを参考に進めてみる。
MVCのうち、viewをまず作成する。
作成したディレクトリへ移動。
# cd /Myapp # script/myapp_create.pl view TT TT
ここで行き詰まる。
Couldn't load helper "Catalyst::Helper::View::TT", "Can't locate Catalyst/Helper/View/TT.pm ・ ・ ・ ・
つまり、まだ入ってないみたいなのでCPANでインスコ。
# cpan cpan >install Catalyst::Helper::View::TT ・ ・ ・ ・ /usr/bin/make install -- OK
よし、無事に入ったようなので改めてview作成。
# script/myapp_create.pl view TT TT exists "/home/makoto/public_html/MyApp/script/../lib/MyApp/View" exists "/home/makoto/public_html/MyApp/script/../t" created "/home/makoto/public_html/MyApp/script/../lib/MyApp/View/TT.pm" created "/home/makoto/public_html/MyApp/script/../t/view_TT.t"
これでview作成完了。
次にMVCのうち、Cのコントローラ部分のMyApp.pmを編集。
コントローラ部分はMyApp/lib/MyApp.pmの部分。
# cd MyApp/lib/ # vi MyApp.pm
MyApp.pmの中身。
package MyApp;
use strict;
use warnings;
use Catalyst::Runtime '5.70';
# Set flags and add plugins for the application
#
# -Debug: activates the debug mode for very useful log messages
# ConfigLoader: will load the configuration from a Config::General file in the
# application's home directory
# Static::Simple: will serve static files from the application's root
# directory
use parent qw/Catalyst/;
our $VERSION = '0.01';
# Configure the application.
#
# Note that settings in myapp.conf (or other external
# configuration file that you set up manually) take precedence
# over this when using ConfigLoader. Thus configuration
# details given here can function as a default configuration,
# with a external configuration file acting as an override for
# local deployment.
__PACKAGE__->config( name => 'MyApp' );
# Start the application
__PACKAGE__->setup(qw/-Debug ConfigLoader Static::Simple/);
=head1 NAME
MyApp - Catalyst based application
=head1 SYNOPSIS
script/myapp_server.pl
=head1 DESCRIPTION
[enter your description here]
=head1 SEE ALSO
L, L
=head1 AUTHOR
root
=head1 LICENSE
This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
1;
まず、どのように動くのか確認するために内容を下記のコードにかえる。
コントローラ部分の動きは後で学ぶ。
package MyApp;
use strict;
use Catalyst qw(
-Debug
);
our $VERSION = '0.01';
__PACKAGE__->config( name => 'MyApp' );
__PACKAGE__->setup(qw/-Debug ConfigLoader Static::Simple/);
sub default : Private {
my ($self, $c) = @_;
$c->res->output('Hello World! <a href="page2/">go to page</a>.');
}
sub page2 : Global {
my ($self, $c) = @_;
$c->stash->{message} = 'Page2';
$c->stash->{template} = 'page2.html';
$c->forward('Hello::V::TT');
}
次にMVCのモデル、ページを作成。
作成場所はMyApp/root/でpage2.htmlを作成。
# vi page2.html <center>[% message %]</center>
これで下準備は完了。
実際に動かしてみる。
# MyApp/script/myapp_server.pl [debug] Debug messages enabled [debug] Statistics enabled [debug] Loaded plugins: .----------------------------------------------------------------------------. | Catalyst::Plugin::ConfigLoader 0.20 | | Catalyst::Plugin::Static::Simple 0.20 | '----------------------------------------------------------------------------' [debug] Loaded dispatcher "Catalyst::Dispatcher" [debug] Loaded engine "Catalyst::Engine::HTTP" [debug] Found home "/home/makoto/public_html/MyApp" [debug] Loaded components: .-----------------------------------------------------------------+----------. | Class | Type | +-----------------------------------------------------------------+----------+ | MyApp::Controller::Root | instance | '-----------------------------------------------------------------+----------' [debug] Loaded Private actions: .----------------------+--------------------------------------+--------------. | Private | Class | Method | +----------------------+--------------------------------------+--------------+ | /default | MyApp::Controller::Root | default | | /end | MyApp::Controller::Root | end | | /page2 | MyApp | page2 | | /index | MyApp::Controller::Root | index | '----------------------+--------------------------------------+--------------' [debug] Loaded Path actions: .-------------------------------------+--------------------------------------. | Path | Private | +-------------------------------------+--------------------------------------+ | / | /default | | / | /index | | /page2 | /page2 | '-------------------------------------+--------------------------------------' [info] MyApp powered by Catalyst 5.7013 You can connect to your server at http://makotoworld.dyndns.org:3000
サーバー立ち上げ完了。
http://makotoworld.dyndns.org:3000にアクセスし動いているか、確認。
無事に動いてます。
次にモデルで作成したpage2のチェック。
http://makotoworld.dyndns.org:3000/page2にアクセス。
これも無事に動いてまする。
今度はコントローラの使い方を調べてみる。



コメントする