add offset function for non-callback driven stuff, add tests
[p5sagit/Devel-Declare.git] / Declare.xs
index be8f478..52b41b2 100644 (file)
@@ -136,6 +136,11 @@ char* dd_get_curstash_name(pTHX) {
   return HvNAME(PL_curstash);
 }
 
+int dd_get_linestr_offset(pTHX) {
+  char* linestr = SvPVX(PL_linestr);
+  return PL_bufptr - linestr;
+}
+
 char* dd_move_past_token (pTHX_ char* s) {
 
   /*
@@ -287,6 +292,12 @@ STATIC OP *dd_ck_const(pTHX_ OP *o) {
 
   o = dd_old_ck_const(aTHX_ o); /* let the original do its job */
 
+  /* if this is set, we just grabbed a delimited string or something,
+     not a bareword, so NO TOUCHY */
+
+  if (PL_lex_stuff)
+    return o;
+
   /* don't try and look this up if it's not a string const */
   if (!SvPOK(cSVOPo->op_sv))
     return o;
@@ -354,6 +365,13 @@ get_curstash_name()
     RETVAL
 
 int
+get_linestr_offset()
+  CODE:
+    RETVAL = dd_get_linestr_offset(aTHX);
+  OUTPUT:
+    RETVAL
+
+int
 toke_scan_word(int offset, int handle_package)
   CODE:
     RETVAL = dd_toke_scan_word(aTHX_ offset, handle_package);