[Bast-commits] r4317 - in trunk/Devel-Declare: . lib/Devel

clkao at dev.catalyst.perl.org clkao at dev.catalyst.perl.org
Mon May 5 09:37:19 BST 2008


Author: clkao
Date: 2008-05-05 09:37:19 +0100 (Mon, 05 May 2008)
New Revision: 4317

Modified:
   trunk/Devel-Declare/Declare.xs
   trunk/Devel-Declare/lib/Devel/Declare.pm
Log:
Make devel::declare parse the part between prototype and
sub body as traits and pass them to the callback.


Modified: trunk/Devel-Declare/Declare.xs
===================================================================
--- trunk/Devel-Declare/Declare.xs	2008-05-05 08:32:54 UTC (rev 4316)
+++ trunk/Devel-Declare/Declare.xs	2008-05-05 08:37:19 UTC (rev 4317)
@@ -8,6 +8,7 @@
 #include <stdio.h>
 #include <string.h>
 
+#define DD_HAS_TRAITS
 #if 0
 #define DD_DEBUG
 #endif
@@ -42,7 +43,7 @@
   char* save_s;
   char tmpbuf[sizeof PL_tokenbuf];
   char found_name[sizeof PL_tokenbuf];
-  char* found_proto = NULL;
+  char* found_proto = NULL, *found_traits = NULL;
   STRLEN len = 0;
   HV *stash;
   HV* is_declarator;
@@ -156,6 +157,23 @@
     if (*s == '(') { /* found a prototype-ish thing */
       save_s = s;
       s = scan_str(s, FALSE, FALSE); /* no keep_quoted, no keep_delims */
+#ifdef DD_HAS_TRAITS
+      {
+          char *traitstart = s = skipspace(s);
+
+          while (*s && *s != '{') ++s;
+          if (*s) {
+              int tlen = s - traitstart;
+              Newx(found_traits, tlen+1, char);
+              Copy(traitstart, found_traits, tlen, char);
+              found_traits[tlen] = 0;
+#ifdef DD_DEBUG
+              printf("found traits..... (%s)\n", found_traits);
+#endif
+          }
+      }
+#endif
+      
       if (SvPOK(PL_lex_stuff)) {
 #ifdef DD_DEBUG
         printf("Found proto %s\n", SvPVX(PL_lex_stuff));
@@ -187,7 +205,8 @@
   cb_args[2] = HvNAME(PL_curstash);
   cb_args[3] = found_name;
   cb_args[4] = found_proto;
-  cb_args[5] = NULL;
+  cb_args[5] = found_traits;
+  cb_args[6] = NULL;
 
   if (len && found_proto)
     in_declare = 2;
@@ -211,6 +230,7 @@
       const int old_len = SvCUR(PL_linestr);
 #ifdef DD_DEBUG
       printf("Got string %s\n", retstr);
+      printf("retstr len: %d, old_len %d\n", strlen(retstr), old_len);
 #endif
       SvGROW(PL_linestr, (STRLEN)(old_len + strlen(retstr)));
       memmove(s+strlen(retstr), s, (PL_bufend - s)+1);

Modified: trunk/Devel-Declare/lib/Devel/Declare.pm
===================================================================
--- trunk/Devel-Declare/lib/Devel/Declare.pm	2008-05-05 08:32:54 UTC (rev 4316)
+++ trunk/Devel-Declare/lib/Devel/Declare.pm	2008-05-05 08:37:19 UTC (rev 4317)
@@ -70,10 +70,10 @@
 my $temp_save;
 
 sub init_declare {
-  my ($usepack, $use, $inpack, $name, $proto) = @_;
+  my ($usepack, $use, $inpack, $name, $proto, $traits) = @_;
   my ($name_h, $XX_h, $extra_code)
        = $declarator_handlers{$usepack}{$use}->(
-           $usepack, $use, $inpack, $name, $proto, defined(wantarray)
+           $usepack, $use, $inpack, $name, $proto, defined(wantarray), $traits
          );
   ($temp_name, $temp_save) = ([], []);
   if ($name) {
@@ -165,8 +165,8 @@
     $setup_for_args{$name} = [
       $flags,
       sub {
-        my ($usepack, $use, $inpack, $name, $proto, $shift_hashref) = @_;
-        my $extra_code = $compile->($name, $proto);
+        my ($usepack, $use, $inpack, $name, $proto, $shift_hashref, $traits) = @_;
+        my $extra_code = $compile->($name, $proto, $traits);
         my $main_handler = sub { shift if $shift_hashref;
           ("DONE", $run->($name, $proto, @_));
         };




More information about the Bast-commits mailing list