Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix indication of line number at which an parsing error occurred. #10

Closed
wants to merge 1 commit into from

2 participants

@moznion

I fixed a problem that showing wrong line number at which an parsing error occurred.
e.g. https://gist.github.com/moznion/5261898

But I have no neat idea, so way of this pull-request maybe uncouth...

@miyagawa
Owner

Fixed by using "# line filename"

@miyagawa miyagawa closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 2 deletions.
  1. +6 −2 lib/Module/CPANfile.pm
  2. +17 −0 t/parse.t
View
8 lib/Module/CPANfile.pm
@@ -149,7 +149,11 @@ EVAL
$err = $@;
}
- if ($err) { die "Parsing $file failed: $err" };
+ if ($err) {
+ my $line_diff = 5;
+ $err =~ s/line (\d*),/sprintf('line %d,', $1 - $line_diff)/e;
+ die "Parsing $file failed: $err";
+ }
return $res;
}
@@ -336,4 +340,4 @@ Tatsuhiko Miyagawa
L<cpanfile>, L<CPAN::Meta>, L<CPAN::Meta::Spec>
-=cut
+=cut
View
17 t/parse.t
@@ -60,4 +60,21 @@ FILE
};
}
+{
+ my $die;
+ local $SIG{__DIE__} = sub { $die = $_[0] };
+
+ my $r = write_cpanfile(<<FILE);
+configure_requires 'ExtUtils::MakeMaker', 5.5;
+
+requires 'DBI';
+requires 'Plack', '0.9970';
+ILLEGAL 'Moose', '< 0.8';
+FILE
+
+ eval { my $file = Module::CPANfile->load };
+
+ like $die, qr/failed: syntax error at \(eval \d+\) line 5,/;
+}
+
done_testing;
Something went wrong with that request. Please try again.