Skip Menu |

This queue is for tickets about the Dispatch-Declare CPAN distribution.

Report information
The Basics
Id: 29150
Status: resolved
Priority: 0/
Queue: Dispatch-Declare

People
Owner: Nobody in particular
Requestors: cpan [...] punch.net
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Feature request: pass arguments into dispatch subs
I want to be able to do this: run $action, @arguments; so that I can pass things into my dispatch subs. Attached is a patch that allows this, and a test file to test it. I also added some semicolons to the docs to make them more consistent.
Subject: handle_args.patch
diff -Naur ../Dispatch-Declare-0.0.6.orig/lib/Dispatch/Declare.pm ./lib/Dispatch/Declare.pm --- ../Dispatch-Declare-0.0.6.orig/lib/Dispatch/Declare.pm 2007-07-13 08:41:40.000000000 -0700 +++ ./lib/Dispatch/Declare.pm 2007-09-04 00:17:01.000000000 -0700 @@ -47,10 +47,10 @@ sub run { my $key = shift; if ( exists $stash->{ uc $key } ) { - return $stash->{ uc $key }->(); + return $stash->{ uc $key }->(@_); } elsif ( exists $stash->{'DEFAULT'} ) { - return $stash->{'DEFAULT'}->(); + return $stash->{'DEFAULT'}->(@_); } } @@ -105,11 +105,11 @@ declare KEY1 => sub { ... - } + }; declare KEY2 => sub { ... - } + }; =item declare_once @@ -117,11 +117,11 @@ declare_once KEY1 => sub { # Set KEY1 ... - } + }; declare_once KEY1 => sub { # Error ... - } + }; =item undeclare diff -Naur ../Dispatch-Declare-0.0.6.orig/t/args.t ./t/args.t --- ../Dispatch-Declare-0.0.6.orig/t/args.t 1969-12-31 16:00:00.000000000 -0800 +++ ./t/args.t 2007-09-04 00:22:25.000000000 -0700 @@ -0,0 +1,22 @@ + +use strict; + +use Test::More tests => 2; + +BEGIN { + use_ok( 'Dispatch::Declare' ); +} + +my $action = 'TEST1'; + +declare_once TEST1 => sub { + return \@_; +}; + + +my @args = ( 'one', 2, 'three' ); + +my $result = run 'TEST1', @args; + +is_deeply( $result, \@args, 'can we pass in args' ); +
From: robo4288 [...] gmail.com
On Tue Sep 04 03:24:57 2007, cpan@punch.net wrote: Show quoted text
> I want to be able to do this: > > run $action, @arguments; > > so that I can pass things into my dispatch subs. > > Attached is a patch that allows this, and a test file to test it. > > I also added some semicolons to the docs to make them more consistent.
Thank you for the patch it has be applied and uploaded to pause.
Resolved a while back