summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-07-23 18:56:20 -0400
committerJesse Luehrs <doy@tozt.net>2013-07-23 18:56:20 -0400
commit60b8b4ddf6ce5280991a87fe3947aa769bf9cb8b (patch)
treeee567c74cf1bcef7d44490f1204135e0ddb18f24
parentec07fc746048ae4e894e7cb327938ccfe3eb7644 (diff)
downloadparse-keyword-60b8b4ddf6ce5280991a87fe3947aa769bf9cb8b.tar.gz
parse-keyword-60b8b4ddf6ce5280991a87fe3947aa769bf9cb8b.zip
pass the keyword name to parser functions
-rw-r--r--Keyword.xs2
-rw-r--r--t/keyword-name.t25
2 files changed, 27 insertions, 0 deletions
diff --git a/Keyword.xs b/Keyword.xs
index 0cad122..a697266 100644
--- a/Keyword.xs
+++ b/Keyword.xs
@@ -65,6 +65,8 @@ static OP *parser_callback(pTHX_ GV *namegv, SV *psobj, U32 *flagsp)
*/
PUSHMARK(SP);
+ mXPUSHp(GvNAME(namegv), GvNAMELEN(namegv));
+ PUTBACK;
count = call_sv(psobj, G_ARRAY);
SPAGAIN;
if (count > 1) {
diff --git a/t/keyword-name.t b/t/keyword-name.t
new file mode 100644
index 0000000..8ab2f44
--- /dev/null
+++ b/t/keyword-name.t
@@ -0,0 +1,25 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+
+BEGIN {
+ package My::Parser;
+ use Exporter 'import';
+ our @EXPORT = 'foo';
+
+ use Parse::Keyword { foo => \&parse_foo };
+
+ sub foo { $_[0] }
+ sub parse_foo {
+ my ($keyword) = @_;
+ return sub { uc($keyword) };
+ }
+
+ $INC{'My/Parser.pm'} = __FILE__;
+}
+
+use My::Parser;
+is(foo, 'FOO');
+
+done_testing;