From: Matt S Trout Date: Fri, 29 Jun 2007 05:20:23 +0000 (+0000) Subject: debug flag, extra test X-Git-Tag: 0.005000~139 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c630715aa8fed80229afaf677e1cfc1206685f89;p=p5sagit%2FDevel-Declare.git debug flag, extra test --- diff --git a/Declare.xs b/Declare.xs index 68f070d..67dc03e 100644 --- a/Declare.xs +++ b/Declare.xs @@ -9,6 +9,14 @@ #include #include +#define DD_DEBUG 0 + +#ifdef DD_DEBUG +#define DD_DEBUG_S printf("Buffer: %s\n", s); +#else +#define DD_DEBUG_S +#endif + #define LEX_NORMAL 10 #define LEX_INTERPNORMAL 9 @@ -54,7 +62,9 @@ STATIC OP *dd_ck_rv2cv(pTHX_ OP *o) { stash = GvSTASH(kGVOP_gv); - /* printf("Checking GV %s -> %s\n", HvNAME(stash), GvNAME(kGVOP_gv)); */ +#ifdef DD_DEBUG + printf("Checking GV %s -> %s\n", HvNAME(stash), GvNAME(kGVOP_gv)); +#endif is_declarator = get_hv("Devel::Declare::declarators", FALSE); @@ -77,20 +87,36 @@ STATIC OP *dd_ck_rv2cv(pTHX_ OP *o) { s = PL_bufptr; /* copy the current buffer pointer */ + DD_DEBUG_S + +#ifdef DD_DEBUG + printf("PL_tokenbuf: %s", PL_tokenbuf); +#endif + + /* + * buffer will be at the beginning of the declarator, -unless- the + * declarator is at EOL in which case it'll be the next useful line + * so we don't short-circuit out if we don't find the declarator + */ + while (s < PL_bufend && isSPACE(*s)) s++; if (memEQ(s, PL_tokenbuf, strlen(PL_tokenbuf))) s += strlen(PL_tokenbuf); - else - return o; + + DD_DEBUG_S /* find next word */ s = skipspace(s); + DD_DEBUG_S + /* 0 in arg 4 is allow_package - not trying that yet :) */ s = scan_word(s, tmpbuf, sizeof tmpbuf, 0, &len); + DD_DEBUG_S + if (len) { cb_args[0] = HvNAME(stash); cb_args[1] = GvNAME(kGVOP_gv); diff --git a/stolen_chunk_of_toke.c b/stolen_chunk_of_toke.c index 5da6095..b570860 100644 --- a/stolen_chunk_of_toke.c +++ b/stolen_chunk_of_toke.c @@ -21,9 +21,16 @@ #define DPTR2FPTR(t,p) ((t)PTR2nat(p)) /* data pointer to function pointer */ #define FPTR2DPTR(t,p) ((t)PTR2nat(p)) /* function pointer to data pointer */ +#define PTR2nat(p) (PTRV)(p) /* pointer to integer of PTRSIZE */ #define MEM_WRAP_CHECK_(n,t) MEM_WRAP_CHECK(n,t), #define Newx(v,n,t) (v = (MEM_WRAP_CHECK_(n,t) (t*)safemalloc((MEM_SIZE)((n)*sizeof(t))))) +/* On MacOS, respect nonbreaking spaces */ +#ifdef MACOS_TRADITIONAL +#define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t') +#else +#define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t') +#endif #define LEX_NORMAL 10 /* normal code (ie not within "...") */ #define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */ diff --git a/t/simple.t b/t/simple.t index 7dfc49c..80772ca 100644 --- a/t/simple.t +++ b/t/simple.t @@ -10,9 +10,21 @@ sub method { use Devel::Declare 'method'; +my ($args1, $args2); + method bar { - my $str = join(', ', @_); - is($str, 'main, baz, quux', 'Method args ok'); + $args1 = join(', ', @_); +}; + +method # blather + baz + # whee +{ + $args2 = join(', ', @_); }; -__PACKAGE__->bar(qw(baz quux)); +__PACKAGE__->bar(qw(1 2)); +__PACKAGE__->baz(qw(3 4)); + +is($args1, 'main, 1, 2', 'Method bar args ok'); +is($args2, 'main, 3, 4', 'Method baz args ok');