initial sketch of shadow_sub and hashref-based callback API
[p5sagit/Devel-Declare.git] / Declare.xs
index c03921f..be8f478 100644 (file)
 # define Newx(v,n,t) New(0,v,n,t)
 #endif /* !Newx */
 
+#if 1
+#define DD_HAS_TRAITS
+#endif
+
 #if 0
 #define DD_DEBUG
 #endif
 
+#define DD_HANDLE_NAME 1
+#define DD_HANDLE_PROTO 2
+#define DD_HANDLE_PACKAGE 8
+
 #ifdef DD_DEBUG
 #define DD_DEBUG_S printf("Buffer: %s\n", s);
 #else
@@ -117,7 +125,7 @@ void dd_set_linestr(pTHX_ char* new_value) {
 }
 
 char* dd_get_lex_stuff(pTHX) {
-  return SvPVX(PL_lex_stuff);
+  return (PL_lex_stuff ? SvPVX(PL_lex_stuff) : "");
 }
 
 char* dd_clear_lex_stuff(pTHX) {
@@ -128,7 +136,7 @@ char* dd_get_curstash_name(pTHX) {
   return HvNAME(PL_curstash);
 }
 
-char* dd_move_past_token(pTHX_ char* s) {
+char* dd_move_past_token (pTHX_ char* s) {
 
   /*
    *   buffer will be at the beginning of the declarator, -unless- the
@@ -142,7 +150,7 @@ char* dd_move_past_token(pTHX_ char* s) {
   return s;
 }
 
-int dd_toke_move_past_token(pTHX_ int offset) {
+int dd_toke_move_past_token (pTHX_ int offset) {
   char* base_s = SvPVX(PL_linestr) + offset;
   char* s = dd_move_past_token(aTHX_ base_s);
   return s - base_s;
@@ -180,10 +188,22 @@ STATIC OP *dd_ck_rv2cv(pTHX_ OP *o) {
   o = dd_old_ck_rv2cv(aTHX_ o); /* let the original do its job */
 
   if (in_declare) {
-    dSP;
-    PUSHMARK(SP);
-    call_pv("Devel::Declare::done_declare", G_VOID|G_DISCARD);
-    in_declare--;
+    cb_args[0] = NULL;
+#ifdef DD_DEBUG
+    printf("Deconstructing declare\n");
+    printf("PL_bufptr: %s\n", PL_bufptr);
+    printf("bufend at: %i\n", PL_bufend - PL_bufptr);
+    printf("linestr: %s\n", SvPVX(PL_linestr));
+    printf("linestr len: %i\n", PL_bufend - SvPVX(PL_linestr));
+#endif
+    call_argv("Devel::Declare::done_declare", G_VOID|G_DISCARD, cb_args);
+#ifdef DD_DEBUG
+    printf("PL_bufptr: %s\n", PL_bufptr);
+    printf("bufend at: %i\n", PL_bufend - PL_bufptr);
+    printf("linestr: %s\n", SvPVX(PL_linestr));
+    printf("linestr len: %i\n", PL_bufend - SvPVX(PL_linestr));
+    printf("actual len: %i\n", strlen(PL_bufptr));
+#endif
     return o;
   }
 
@@ -195,11 +215,23 @@ STATIC OP *dd_ck_rv2cv(pTHX_ OP *o) {
   if (PL_lex_state != LEX_NORMAL && PL_lex_state != LEX_INTERPNORMAL)
     return o; /* not lexing? */
 
+#ifdef DD_DEBUG
+  printf("Checking GV %s -> %s\n", HvNAME(GvSTASH(kGVOP_gv)), GvNAME(kGVOP_gv));
+#endif
+
   dd_flags = dd_is_declarator(aTHX_ GvNAME(kGVOP_gv));
 
   if (dd_flags == -1)
     return o;
 
+#ifdef DD_DEBUG
+  printf("dd_flags are: %i\n", dd_flags);
+#endif
+
+#ifdef DD_DEBUG
+  printf("PL_tokenbuf: %s\n", PL_tokenbuf);
+#endif
+
   dd_linestr_callback(aTHX_ "rv2cv", GvNAME(kGVOP_gv));
 
   return o;