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' );
+