This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Allow overriding line numbers and files while parsing strings
authorSteffen Mueller <smueller@cpan.org>
Sat, 16 Apr 2011 14:57:36 +0000 (16:57 +0200)
committerSteffen Mueller <smueller@cpan.org>
Tue, 12 Jul 2011 18:54:51 +0000 (20:54 +0200)
When parsing typemaps from strings, we used to print in-string
line numbers and <string> as the file name. In case of embedded
typemaps in XS code, we really want to refer back to the line
number and name of the XS file. This is now possible.

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

index 9bb5307..0bc08cd 100644 (file)
@@ -93,7 +93,7 @@ sub new {
 sub _init {
   my $self = shift;
   if (defined $self->{string}) {
 sub _init {
   my $self = shift;
   if (defined $self->{string}) {
-    $self->_parse(\($self->{string}));
+    $self->_parse(\($self->{string}), $self->{lineno_offset}, $self->{fake_filename});
     delete $self->{string};
   }
   elsif (defined $self->{file} and -e $self->{file}) {
     delete $self->{string};
   }
   elsif (defined $self->{file} and -e $self->{file}) {
@@ -102,7 +102,7 @@ sub _init {
              . $self->{file} . "' for reading: $!";
     local $/ = undef;
     my $string = <$fh>;
              . $self->{file} . "' for reading: $!";
     local $/ = undef;
     my $string = <$fh>;
-    $self->_parse(\$string, $self->{file});
+    $self->_parse(\$string, $self->{lineno_offset}, $self->{file});
   }
 }
 
   }
 }
 
@@ -816,6 +816,8 @@ sub validate {
 sub _parse {
   my $self = shift;
   my $stringref = shift;
 sub _parse {
   my $self = shift;
   my $stringref = shift;
+  my $lineno_offset = shift;
+  $lineno_offset = 0 if not defined $lineno_offset;
   my $filename = shift;
   $filename = '<string>' if not defined $filename;
 
   my $filename = shift;
   $filename = '<string>' if not defined $filename;
 
@@ -830,7 +832,7 @@ sub _parse {
   # TODO order of sections, multiple sections of same type
   # Heavily influenced by ExtUtils::ParseXS
   my $section = 'typemap';
   # TODO order of sections, multiple sections of same type
   # Heavily influenced by ExtUtils::ParseXS
   my $section = 'typemap';
-  my $lineno = 0;
+  my $lineno = $lineno_offset;
   my $junk = "";
   my $current = \$junk;
   my @input_expr;
   my $junk = "";
   my $current = \$junk;
   my @input_expr;