Change ValidProtoString() to valid_proto_string()
authorJames E. Keenan <jkeenan@cpan.org>
Sun, 6 Feb 2011 10:53:59 +0000 (11:53 +0100)
committerSteffen Mueller <smueller@cpan.org>
Tue, 12 Jul 2011 18:53:50 +0000 (20:53 +0200)
and move its definition to Utilities.pm

dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm
dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Constants.pm
dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Utilities.pm

index fda7c25..e47457d 100644 (file)
@@ -9,12 +9,14 @@ use Exporter;
 use File::Basename;
 use File::Spec;
 use Symbol;
+use ExtUtils::ParseXS::Constants ();
 use ExtUtils::ParseXS::CountLines;
 use ExtUtils::ParseXS::Utilities qw(
   standard_typemap_locations
   trim_whitespace
   tidy_type
   C_string
+  valid_proto_string
 );
 
 our (@ISA, @EXPORT_OK, $VERSION);
@@ -25,9 +27,6 @@ $VERSION = eval $VERSION if $VERSION =~ /_/;
 
 # use strict;  # One of these days ...
 
-my(@XSStack);    # Stack of conditionals and INCLUDEs
-my($XSS_work_idx, $cpp_next_tmp);
-
 our (
   $ProtoUsed, @InitFileCode, $FH, $proto_re, $Overload, $errors, $Fallback, 
   $hiertype, $WantPrototypes, $WantVersionChk, $WantLineNumbers, $filepathname, 
@@ -40,7 +39,7 @@ our (
   @line_no, $ret_type, $func_name, $Full_func_name, $Packprefix, $Packid,  
   %XsubAliases, %XsubAliasValues, %Interfaces, @Attributes, %outargs, $pname,
   $thisdone, $retvaldone, $deferred, $gotRETVAL, $condnum, $cond,
-  $RETVAL_code, $name_printed, $func_args, 
+  $RETVAL_code, $name_printed, $func_args, @XSStack, 
 );
 #our $DoSetMagic;
 
@@ -79,13 +78,14 @@ sub process_file {
     $SymSet = new ExtUtils::XSSymSet 28;
   }
   @XSStack = ({type => 'none'});
-  ($XSS_work_idx, $cpp_next_tmp) = (0, "XSubPPtmpAAAA");
-  @InitFileCode = ();
-  $FH = Symbol::gensym();
-  $proto_re = "[" . quotemeta('\$%&*@;[]_') . "]";
-  $Overload = 0;
-  $errors = 0;
-  $Fallback = '&PL_sv_undef';
+  my $XSS_work_idx = 0;
+  my $cpp_next_tmp = 'XSubPPtmpAAAA';
+  @InitFileCode = @ExtUtils::ParseXS::Constants::InitFileCode;
+  $FH           = $ExtUtils::ParseXS::Constants::FH;
+  $proto_re     = $ExtUtils::ParseXS::Constants::proto_re;
+  $Overload     = $ExtUtils::ParseXS::Constants::Overload;
+  $errors       = $ExtUtils::ParseXS::Constants::errors;
+  $Fallback     = $ExtUtils::ParseXS::Constants::Fallback;
 
   # Most of the 1500 lines below uses these globals.  We'll have to
   # clean this up sometime, probably.  For now, we just pull them out
@@ -181,7 +181,7 @@ sub process_file {
         # prototype defaults to '$'
         $proto = "\$" unless $proto;
         warn("Warning: File '$typemap' Line $. '$line' Invalid prototype '$proto'\n")
-          unless ValidProtoString($proto);
+          unless valid_proto_string($proto);
         $proto_letter{$type} = C_string($proto);
       }
       elsif (/^\s/) {
@@ -1433,7 +1433,7 @@ sub PROTOTYPE_handler () {
       # remove any whitespace
       s/\s+//g;
       death("Error: Invalid prototype '$_'")
-        unless ValidProtoString($_);
+        unless valid_proto_string($_);
       $ProtoThisXSUB = C_string($_);
     }
   }
@@ -1635,16 +1635,6 @@ EOF
   return 1;
 }
 
-sub ValidProtoString ($) {
-  my($string) = @_;
-
-  if ( $string =~ /^$proto_re+$/ ) {
-    return $string;
-  }
-
-  return 0;
-}
-
 sub ProtoString ($) {
   my ($type) = @_;
 
index f53b574..ae07b00 100644 (file)
@@ -23,9 +23,6 @@ Nothing is exported.  Use fully qualified variable names.
 
 =cut
 
-our @XSStack      = ({type => 'none'});
-our $XSS_work_idx = 0;
-our $cpp_next_tmp = "XSubPPtmpAAAA";
 our @InitFileCode = ();
 our $FH           = Symbol::gensym();
 our $proto_re     = "[" . quotemeta('\$%&*@;[]') . "]";
index 7ce3051..bd6d36f 100644 (file)
@@ -3,6 +3,8 @@ use strict;
 use warnings;
 use Exporter;
 use File::Spec;
+use lib qw( lib );
+use ExtUtils::ParseXS::Constants ();
 our (@ISA, @EXPORT_OK);
 @ISA = qw(Exporter);
 @EXPORT_OK = qw(
@@ -10,6 +12,7 @@ our (@ISA, @EXPORT_OK);
   trim_whitespace
   tidy_type
   C_string
+  valid_proto_string
 );
 
 =head1 NAME
@@ -208,4 +211,35 @@ sub C_string {
   $string;
 }
 
+=head2 C<valid_proto_string()>
+
+=over 4
+
+=item * Purpose
+
+Validate prototype string.
+
+=item * Arguments
+
+String needing checking.
+
+=item * Return Value
+
+Upon success, returns the same string passed as argument.
+
+Upon failure, returns C<0>.
+
+=back
+
+=cut
+
+sub valid_proto_string {
+  my($string) = @_;
+
+  if ( $string =~ /^$ExtUtils::ParseXS::Constants::proto_re+$/ ) {
+    return $string;
+  }
+
+  return 0;
+}
 1;