2012-06-20 22 views

Odpowiedz

8

:CaptureArgs(N) pasuje, jeśli zostało przynajmniej N args. Jest używany dla nie-terminali Chained handlers.

:Args(N) pasuje tylko wtedy, gdy pozostało dokładnie N argumentów.

Przykładowo

sub catalog : Chained : CaptureArgs(1) { 
    my ($self, $c, $arg) = @_; 
    ... 
} 

sub item : Chained('catalog') : Args(2) { 
    my ($self, $c, $arg1, $arg2) = @_; 
    ... 
} 

dopasowania

/catalog/*/item/*/* 
+0

To ściąga go ładnie, dzięki. – friedo

5

CaptureArgs stosuje się w połączonych była metod Catalyst.

Args oznacza koniec metody łańcuchowej.

Dla ex:

sub base_method : Chained('/') :PathPart("account") :CaptureArgs(0) 
{ 

} 
sub after_base : Chained('base_method') :PathPart("org") :CaptureArgs(2) 
{ 

} 
sub base_end : Chained('after_base') :PathPart("edit") :Args(1) 
{ 

} 

powyższych metod W powiązanych dopasować /account/org/*/*/edit/*.

Tutaj base_end jest końcową metodą łańcucha. Aby oznaczyć koniec połączonego działania, użyto Args. Jeśli użyjemy CaptureArgs oznacza to, że łańcuch nadal działa.

Args jest również stosowany w innych metodach katalizatora do określania argumentów metody.

również z CPAN Catalyst::DispatchType::Chained:

The endpoint of the chain specifies how many arguments it 
gets through the Args attribute. :Args(0) would be none at all, 
:Args without an integer would be unlimited. The path parts that 
aren't endpoints are using CaptureArgs to specify how many parameters 
they expect to receive. 
Powiązane problemy