Reduce code duplication by using the same prototype regexp
authorSteffen Mueller <smueller@cpan.org>
Fri, 11 Feb 2011 13:37:33 +0000 (14:37 +0100)
committerSteffen Mueller <smueller@cpan.org>
Tue, 12 Jul 2011 18:54:48 +0000 (20:54 +0200)
dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Constants.pm
dist/ExtUtils-ParseXS/lib/ExtUtils/Typemaps.pm

index 8631063..1af0685 100644 (file)
@@ -31,6 +31,8 @@ our $errors          = 0;
 
 our $Fallback        = '&PL_sv_undef'; # FIXME Check: Is this a constant?
 
+# Note that to reduce maintenance, $PrototypeRegexp is used
+# by ExtUtils::Typemaps, too!
 our $PrototypeRegexp = "[" . quotemeta('\$%&*@;[]_') . "]";
 our @XSKeywords      = qw( 
   REQUIRE BOOT CASE PREINIT INPUT INIT CODE PPCODE
index cfda24b..c049cbe 100644 (file)
@@ -5,8 +5,8 @@ use warnings;
 our $VERSION = '1.00';
 use Carp qw(croak);
 
-our $Proto_Regexp = "[" . quotemeta('\$%&*@;[]_') . "]"; # TODO: Use ExtUtils::ParseXS' constant instead
-
+require ExtUtils::ParseXS;
+require ExtUtils::ParseXS::Constants;
 require ExtUtils::Typemaps::InputMap;
 require ExtUtils::Typemaps::OutputMap;
 require ExtUtils::Typemaps::Type;
@@ -486,7 +486,7 @@ sub as_string {
   push @code, "TYPEMAP\n";
   foreach my $entry (@$typemap) {
     # type kind proto
-    # /^(.*?\S)\s+(\S+)\s*($Proto_Regexp*)$/o
+    # /^(.*?\S)\s+(\S+)\s*($ExtUtils::ParseXS::Constants::PrototypeRegexp*)$/o
     push @code, $entry->ctype . "\t" . $entry->xstype
               . ($entry->proto ne '' ? "\t".$entry->proto : '') . "\n";
   }
@@ -615,7 +615,7 @@ sub _parse {
       my $line = $_;
       s/^\s+//; s/\s+$//;
       next if /^#/ or /^$/;
-      my($type, $kind, $proto) = /^(.*?\S)\s+(\S+)\s*($Proto_Regexp*)$/o
+      my($type, $kind, $proto) = /^(.*?\S)\s+(\S+)\s*($ExtUtils::ParseXS::Constants::PrototypeRegexp*)$/o
         or warn("Warning: File '$filename' Line $lineno '$line' TYPEMAP entry needs 2 or 3 columns\n"),
            next;
       #$proto = '' if not $proto;
@@ -675,7 +675,7 @@ sub _tidy_type {
 # taken from ExtUtils::ParseXS
 sub _valid_proto_string {
   my $string = shift;
-  if ($string =~ /^$Proto_Regexp+$/o) {
+  if ($string =~ /^$ExtUtils::ParseXS::Constants::PrototypeRegexp+$/o) {
     return $string;
   }