summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorShawn M Moore <sartak@bestpractical.com>2011-01-26 21:31:55 -0500
committerShawn M Moore <sartak@bestpractical.com>2011-01-26 22:01:43 -0500
commit5617e9667fce453ffa66029ebc10c972a3066725 (patch)
treed8dbe1c3ddb9000cc215f4998c88c0398f5cf8bc /lib
parentc43189112c58a6c5c771c7a52d11fb8e6b79b16b (diff)
downloadeval-closure-5617e9667fce453ffa66029ebc10c972a3066725.tar.gz
eval-closure-5617e9667fce453ffa66029ebc10c972a3066725.zip
Add a terse_error parameter to eval_closure
Diffstat (limited to 'lib')
-rw-r--r--lib/Eval/Closure.pm16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/Eval/Closure.pm b/lib/Eval/Closure.pm
index 48f9258..6a1f41e 100644
--- a/lib/Eval/Closure.pm
+++ b/lib/Eval/Closure.pm
@@ -83,6 +83,12 @@ parameter lets you override that to something more useful (for instance,
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
@@ -98,8 +104,14 @@ sub eval_closure {
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;
}