summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-08-19 09:31:05 -0500
committerJesse Luehrs <doy@tozt.net>2012-08-19 09:31:20 -0500
commite1b5c02916ed9b248f9afcc4260b231e6e03202a (patch)
tree8365b736be86219d36b0bb29c772312d882ada0d
parent5d58a24acf4361c2dd5ec1ed29d4cab4853d0adb (diff)
downloadfun-e1b5c02916ed9b248f9afcc4260b231e6e03202a.tar.gz
fun-e1b5c02916ed9b248f9afcc4260b231e6e03202a.zip
allow "fun Foo::foo ..."
-rw-r--r--Fun.xs14
-rw-r--r--t/package.t16
2 files changed, 28 insertions, 2 deletions
diff --git a/Fun.xs b/Fun.xs
index 9488c80..e808cd7 100644
--- a/Fun.xs
+++ b/Fun.xs
@@ -248,8 +248,18 @@ static OP *parse_fun(pTHX_ GV *namegv, SV *psobj, U32 *flagsp)
floor = start_subparse(0, CVf_ANON);
lex_read_space(0);
- if (isIDFIRST(*(PL_parser->bufptr))) {
- function_name = parse_idword("");
+ if (isIDFIRST(*(PL_parser->bufptr)) || *(PL_parser->bufptr) == ':') {
+ function_name = sv_2mortal(newSVpvs(""));
+ while (isIDFIRST(*(PL_parser->bufptr)) || *(PL_parser->bufptr) == ':') {
+ if (lex_peek_unichar(0) == ':') {
+ demand_unichar(':', DEMAND_IMMEDIATE);
+ demand_unichar(':', DEMAND_IMMEDIATE);
+ sv_catpvs(function_name, "::");
+ }
+ else {
+ sv_catsv(function_name, parse_idword(""));
+ }
+ }
}
lex_read_space(0);
diff --git a/t/package.t b/t/package.t
new file mode 100644
index 0000000..2e672d1
--- /dev/null
+++ b/t/package.t
@@ -0,0 +1,16 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+
+use Fun;
+
+fun Foo::foo ($x, $y) {
+ $x + $y;
+}
+
+ok(!main->can('foo'));
+ok(Foo->can('foo'));
+is(Foo::foo(1, 2), 3);
+
+done_testing;