2012-06-20 14 views

risposta

8

:CaptureArgs(N) corrispondenze se sono presenti almeno N args. Viene utilizzato per gestori non terminalati.

:Args(N) corrisponde solo se sono presenti esattamente N args.

Ad esempio,

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

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

partite

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

che cancella in su bene, grazie. – friedo

5

CaptureArgs è utilizzato nei metodi concatenati in Catalyst.

Args indica la fine del metodo concatenato.

Per esempio:

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) 
{ 

} 

Sopra metodi concatenati corrispondono /account/org/*/*/edit/*.

Qui base_end è il metodo fine chain.To segno di fine d'azione incatenato Args si è utilizzato used.If CaptureArgs che significa che la catena è ancora in corso.

Args viene utilizzato anche in altri metodi di catalizzatore per specificare gli argomenti del metodo.

anche da 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. 
Problemi correlati