Hatena::Groupcatalyst

LAPISLAZULI HILL#Catalyst このページをアンテナに追加 RSSフィード

2007-01-05

[][]Catalyst in Chains#02 Catalyst in Chains#02 - LAPISLAZULI HILL#Catalyst を含むブックマーク はてなブックマーク - Catalyst in Chains#02 - LAPISLAZULI HILL#Catalyst Catalyst in Chains#02 - LAPISLAZULI HILL#Catalyst のブックマークコメント

Chain#01 - LAPISLAZULI HILL#Catalyst - Catalystグループの役に立たないメモの続き

Chainedをふたつ(NG)

ちょっと強引だけどこんなのはどうだ

sub fromlanguage : Chained PathPart('') CaptureArgs(1) {
    my ($self, $c, $fromlanguage) = @_;
    $c->stash->{fromlanguage}   = $fromlanguage;
}

sub language : Chained PathPart('fromlanguage') CaptureArgs(1) {
    my ($self, $c, $language) = @_;
    $c->stash->{language}   = $language;
}

sub show_hoge : Chained('fromlanguage') Chained('language') PathPart('hoge') Args(1) {
    my ($self, $c, $args) = @_;
    $c->response->body( $c->stash->{fromlanguage} ." from " .$c->stash->{language} .": hoge : $args");
}
[debug] Loaded Chained actions:
.-------------------------------------+--------------------------------------.
| Path Spec                           | Private                              |
+-------------------------------------+--------------------------------------+
| /*/hoge/*                           | /fromlanguage (1)                    |
|                                     | => /show_hoge                        |
'-------------------------------------+--------------------------------------'

動くけど思ったのとは違う

あえてこんなのは?

sub fromlanguage : Chained PathPart('') CaptureArgs(1) {
    my ($self, $c, $fromlanguage) = @_;
    $c->stash->{fromlanguage}   = $fromlanguage;
}

sub language : Chained PathPart('fromlanguage') CaptureArgs(1) {
    my ($self, $c, $language) = @_;
    $c->stash->{language}   = $language;
}

sub show_hoge : Chained('fromlanguage/language') PathPart('hoge') Args(1) {
    my ($self, $c, $args) = @_;
    $c->response->body( $c->stash->{fromlanguage} ." from " .$c->stash->{language} .": hoge : $args");
}
[debug] Loaded Chained actions:
.-------------------------------------+--------------------------------------.
| Path Spec                           | Private                              |
+-------------------------------------+--------------------------------------+
'-------------------------------------+--------------------------------------'

***空っぽだ!***

CaptureArgsを2にしてみた(*/*/hoge/*)

sub language : Chained PathPart('') CaptureArgs(2) {
    my ($self, $c, $language, $tolanguage) = @_;
    $c->stash->{language}   = $language;
    $c->stash->{tolanguage} = $tolanguage;
}

sub show_hoge : Chained('language') PathPart('hoge') Args(1) {
    my ($self, $c, $args) = @_;
    $c->response->body( $c->stash->{language} . " to " . $c->stash->{tolanguage} .": hoge : $args");
}
[debug] Loaded Chained actions:
.-------------------------------------+--------------------------------------.
| Path Spec                           | Private                              |
+-------------------------------------+--------------------------------------+
| /*/*/hoge/*                         | /language (2)                        |
|                                     | => /show_hoge                        |
'-------------------------------------+--------------------------------------'

http://localhost:3000/jp/en/hoge/12345

jp to en: hoge : 12345

これがほしかった動作だ!

languageでふたつの引数を取ることができた

PathPartをふたつ(NG)

sub language : Chained PathPart('') CaptureArgs(1) {
    my ($self, $c, $language) = @_;
    $c->stash->{language}   = $language;
}

sub edit_hoge : Chained('language') PathPart('hoge') Args(1) PathPart('edit'){
    my ($self, $c, $args) = @_;
    $c->response->body( $c->stash->{language}  .": hoge : $args : edit");
}
Multiple PathPart attributes not supported registering edit_hoge at /home/lapis25/perl/lib/Catalyst/Dispatcher.pm line 409
Compilation failed in require at script/myapp_server.pl line 53.

これはエラーになる.確かに意味は無いな.Argsを2にするんだろう

ddeqcaddeqca2007/04/11 12:47<a href=http://roccofoloper.sblog.cz>sauna belt</a> sauna belt http://roccofoloper.sblog.cz sauna belt

トラックバック - http://catalyst.g.hatena.ne.jp/lapis25/20070105