diff options
author | Jesse Luehrs <doy@tozt.net> | 2010-11-10 05:13:27 -0600 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2010-11-10 05:13:27 -0600 |
commit | fe890fb97648df1253becf110e4e4dfa3c2c8015 (patch) | |
tree | b007c3cbfd5efe61754da18a46880337b82c236b /lib | |
parent | 09e99c47aa98facc78b39e4931c12527a393dd48 (diff) | |
download | eval-closure-fe890fb97648df1253becf110e4e4dfa3c2c8015.tar.gz eval-closure-fe890fb97648df1253becf110e4e4dfa3c2c8015.zip |
use Devel::Hints where possible
this will avoid breaking memoization when generating coderefs with
descriptions, and should be more robust and useful
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Eval/Closure.pm | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/Eval/Closure.pm b/lib/Eval/Closure.pm index b03df5b..ee93a7a 100644 --- a/lib/Eval/Closure.pm +++ b/lib/Eval/Closure.pm @@ -8,11 +8,14 @@ use Sub::Exporter -setup => { # ABSTRACT: safely and cleanly create closures via string eval use Carp; +use Devel::Hints qw(cop_file cop_line); use overload (); use Memoize; use Scalar::Util qw(reftype); use Try::Tiny; +use constant USE_DEVEL_HINTS => ($] >= 5.010); + =head1 SYNOPSIS use Eval::Closure; @@ -93,14 +96,23 @@ sub eval_closure { $args{source} = _canonicalize_source($args{source}); _validate_env($args{environment} ||= {}); - $args{source} = _line_directive($args{description}) . $args{source} - if defined $args{description}; + if (!USE_DEVEL_HINTS) { + $args{source} = _line_directive($args{description}) . $args{source} + if defined $args{description}; + } my ($code, $e) = _clean_eval_closure(@args{qw(source environment)}); croak("Failed to compile source: $e\n\nsource:\n$args{source}") unless $code; + if (USE_DEVEL_HINTS) { + if (defined $args{description}) { + cop_file($code, $args{description}); + cop_line($code, 1); + } + } + return $code; } @@ -147,7 +159,7 @@ sub _validate_env { sub _line_directive { my ($description) = @_; - return qq{#line 1 "$description"\n}; + return qq{#line 0 "$description"\n}; } sub _clean_eval_closure { |