Posts tagged: catalyst

同一 Action 名の Path Spec を実装するには Chained を使う

By admin | 2009年5月19日

/hoge/*

今まで上記のような Path Spec を実装するときは

sub hoge : Args(1) {
    my $self = shift;
    my ($c, @args) = @_;
}

こんな感じでやってた。

/hoge
/hoge/*
/hoge/*/*

で、今回はこういう Path Spec を実装したかったので
同じようにだけでできるかと思ってやったら
dispatch されなくなってできなかった。

sub hoge : Args(0) {
    my $self = shift;
    my ($c) = @_;
}
sub hoge : Args(1) {
    my $self = shift;
    my ($c, @args) = @_;

}
sub hoge : Args(2) {
        my $self = shift;
    my ($c, @args) = @_;

}

で、それを sasata299 が解決してくれた。GJ
Chained を使えばいいらしい。

sub chain : Chained('/') PathPart('') CaptureArgs(0) {
        my $self = shift;
    my ($c) = @_;

}
sub hoge1 : Chained('chain') PathPart('hoge')  Args(0) {
    my $self = shift;
    my ($c) = @_;
}
sub hoge2 : Chained('chain') PathPart('hoge')  Args(1) {
    my $self = shift;
    my ($c, @args) = @_;

}
sub hoge3 : Chained('chain') PathPart('hoge')  Args(2) {
    my $self = shift;
    my ($c, @args) = @_;
}

chained の使い方については sasata299
まとめてくれているので分かりやすかった。
CatalystのChainedアクションを使いこなすための3つのルール

また CatalystのChainedアクションの連鎖を止める方法 このエントリーも併せてみとくといいかも。

多謝多謝

追記 2009-05-19 12:50:11

id:typester さんに Path アクションでやる方法を教えてもらった。(TL)

sub hoge1 :P ath('hoge') :Args(2) {
    my $self = shift;
    my ($c) = @_;
}

sub hoge2 :P ath('hoge') :Args(1) {
    my $self = shift;
    my ($c, @args) = @_;

}

sub hoge3 :P ath('hoge') :Args(0) {
        my $self = shift;
    my ($c) = @_;

}

さらに注意点も教えてもらった。
以下 TL の引用。

  • Pathアクションは同じパスだと後から書いた方が優先されるので、Argsは多い順に定義しないとダメ
  • Args多いのを後から書くとそれに全部持って行かれる
  • さらにちなむと index :P ath とか default :P ath とかはどこに書いても優先されるけど、これは専用のDispatchTypeがあり、Pathアクションではないのです

勉強になった。色々な方法があってやっぱおもしろい。
ありがとうございました〜

Catalyst::Plugin::Session::State::URI が ‘external URL stays untouched’ とエラーがでインストールできない

By admin | 2009年3月22日

原因は URI::Find が2009/03/19にアップデートされたらしい。
それを使うと Catalyst::Plugin::Session::State::URI をいれようとすると下記のようなエラーがでる。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
PERL_DL_NONLAZY=1 /opt/local/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'inc', 'blib/lib', 'blib/arch')" t/01use.t t/02pod.t t/03podcoverage.t t/basic.t t/live_rewrite.t t/live_uri_for.t t/param.t
t/01use.t .......... ok
t/02pod.t .......... skipped: set TEST_POD to enable this test
t/03podcoverage.t .. skipped: set TEST_POD to enable this test
t/basic.t .......... 1/51
#   Failed test 'external URL stays untouched'
#   at t/basic.t line 131.
#          got: 'foo <ahref="http://www.woobling.org/"></a> blah'
#     expected: 'foo <a href="http://www.woobling.org/"></a> blah'
t/basic.t .......... 31/51 # Looks like you failed 1 test of 51.
t/basic.t .......... Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/51 subtests
t/live_rewrite.t ... ok
t/live_uri_for.t ... ok
t/param.t .......... 1/28
#   Failed test 'external URL stays untouched'
#   at t/param.t line 100.
#          got: 'foo <ahref=%22http://www.woobling.org/?sid=qux"></a> blah'
#     expected: 'foo <a href="http://www.woobling.org/"></a> blah'
# Looks like you failed 1 test of 28.
t/param.t .......... Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/28 subtests

インストールされているモジュールのバージョン

- Catalyst::Plugin::Session ...loaded. (0.20 >= 0.06)
- URI                       ...loaded. (1.37)
- URI::QueryParam           ...loaded. (0)
- URI::Find                 ...loaded. (20090319)
- HTML::TokeParser::Simple  ...loaded. (3.15)
- MIME::Types               ...loaded. (1.27)
- Test::MockObject          ...loaded. (1.09 >= 1.01)
- MRO::Compat               ...loaded. (0.09)

URI::Find のバージョンを 0.16 に変更してやるとインストールできた。
ちなみに試した環境は Mac(Leopard) です。
これでようやく Task::Catalyst がはいった。。。。

WordPress Themes