मैं आमतौर पर इन दो विकल्पों के अलग-अलग क्रमपरिवर्तनों की कोशिश कर रहा हूं, लेकिन मैं अभी भी यह नहीं कह सकता कि मैं ठीक से जानता हूं कि वे क्या करते हैं। क्या कोई ठोस उदाहरण है जो अंतर को दर्शाता है?के बीच क्या अंतर है: Args और: Catalyst में CaptureArgs?
10
A
उत्तर
8
:CaptureArgs(N)
यदि कम से कम एन तर्क शेष हैं तो मिलान करें। इसका उपयोग गैर-टर्मिनल चेनड हैंडलर के लिए किया जाता है।
:Args(N)
केवल तभी मेल खाते हैं जब बिल्कुल एन तर्क शेष हैं।
उदाहरण के लिए,
sub catalog : Chained : CaptureArgs(1) {
my ($self, $c, $arg) = @_;
...
}
sub item : Chained('catalog') : Args(2) {
my ($self, $c, $arg1, $arg2) = @_;
...
}
मैचों
/catalog/*/item/*/*
5
CaptureArgs
उत्प्रेरक में जंजीर तरीकों में प्रयोग किया जाता है।
Args
जंजीर विधि के अंत को चिह्नित करता है।
पूर्व के लिए:
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)
{
}
श्रृंखलित तरीकों से ऊपर /account/org/*/*/edit/*
मेल खाते हैं।
यहाँ base_end
श्रृंखलित कार्रवाई Args
है used.If CaptureArgs
प्रयोग किया जाता है इसका मतलब है कि श्रृंखला अभी भी चल रहा है की chain.To निशान अंत के अंत तरीका है।
Args
विधि के तर्कों को निर्दिष्ट करने के लिए उत्प्रेरक के अन्य तरीकों में भी प्रयोग किया जाता है।
:
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.
कि यह अच्छी तरह से ऊपर साफ करता है, धन्यवाद। – friedo