L<Moose> overrides the description for accessors to something like "accessor
foo at MyClass.pm, line 123").
+=item terse_error
+
+Normally, this function appends the source code that failed to compile, and
+prepends some explanatory text. Setting this option to true suppresses that
+behavior so you get only the compilation error that Perl actually reported.
+
=back
=cut
my ($code, $e) = _clean_eval_closure(@args{qw(source environment)});
- croak("Failed to compile source: $e\n\nsource:\n$args{source}")
- unless $code;
+ if (!$code) {
+ if ($args{terse_error}) {
+ die "$e\n";
+ }
+ else {
+ croak("Failed to compile source: $e\n\nsource:\n$args{source}")
+ }
+ }
return $code;
}
"gives us compile errors properly"
);
+like(
+ exception { eval_closure(source => 'sub { $x }') },
+ qr/sub \s* { \s* \$x \s* }/x,
+ "without terse_error, includes the source code"
+);
+
+unlike(
+ exception { eval_closure(source => 'sub { $x }', terse_error => 1) },
+ qr/sub \s* { \s* \$x \s* }/x,
+ "with terse_error, does not include the source code"
+);
+
done_testing;