Add method to get ANSIfied code
authorSteffen Mueller <smueller@cpan.org>
Fri, 11 Feb 2011 18:24:21 +0000 (19:24 +0100)
committerSteffen Mueller <smueller@cpan.org>
Tue, 12 Jul 2011 18:54:48 +0000 (20:54 +0200)
This is done to all of the code in EU::PXS anyway, so why not
have a nice method for it?

dist/ExtUtils-ParseXS/lib/ExtUtils/Typemaps/InputMap.pm
dist/ExtUtils-ParseXS/lib/ExtUtils/Typemaps/OutputMap.pm

index 9a1cdcd..8c28aec 100644 (file)
@@ -2,7 +2,6 @@ package ExtUtils::Typemaps::InputMap;
 use 5.006001;
 use strict;
 use warnings;
-our $VERSION = '0.05';
 use Carp qw(croak);
 
 =head1 NAME
@@ -75,6 +74,26 @@ sub xstype {
   return $_[0]->{xstype};
 }
 
+=head2 cleaned_code
+
+Returns a cleaned-up copy of the code to which certain transformations
+have been applied to make it more ANSI compliant.
+
+=cut
+
+sub cleaned_code {
+  my $self = shift;
+  my $code = $self->code;
+
+  $code =~ s/;*\s+\z//;
+
+  # Move C pre-processor instructions to column 1 to be strictly ANSI
+  # conformant. Some pre-processors are fussy about this.
+  $code =~ s/^\s+#/#/mg;
+
+  return $code;
+}
+
 =head1 SEE ALSO
 
 L<ExtUtils::Typemaps>
index 3c04e1e..31b7312 100644 (file)
@@ -2,7 +2,6 @@ package ExtUtils::Typemaps::OutputMap;
 use 5.006001;
 use strict;
 use warnings;
-our $VERSION = '0.05';
 use Carp qw(croak);
 
 =head1 NAME
@@ -75,6 +74,24 @@ sub xstype {
   return $_[0]->{xstype};
 }
 
+=head2 cleaned_code
+
+Returns a cleaned-up copy of the code to which certain transformations
+have been applied to make it more ANSI compliant.
+
+=cut
+
+sub cleaned_code {
+  my $self = shift;
+  my $code = $self->code;
+
+  # Move C pre-processor instructions to column 1 to be strictly ANSI
+  # conformant. Some pre-processors are fussy about this.
+  $code =~ s/^\s+#/#/mg;
+
+  return $code;
+}
+
 =head1 SEE ALSO
 
 L<ExtUtils::Typemaps>