$args{source} = _canonicalize_source($args{source});
_validate_env($args{environment} ||= {});
+ my $should_set_description = defined $args{description} && !($^P & 0x10);
+
$args{source} = _line_directive(@args{qw(line description)})
. $args{source}
- if defined $args{description} && !($^P & 0x10);
+ if $should_set_description;
+
+ my $existed_before;
+ $existed_before = exists $::{"_<$args{description}"}
+ if $should_set_description;
my ($code, $e) = _clean_eval_closure(@args{qw(source environment)});
+ if (!$existed_before && $should_set_description) {
+ # this will be meaningless, and just leaks memory
+ delete $::{"_<$args{description}"};
+ }
+
if (!$code) {
if ($args{terse_error}) {
die "$e\n";
--- /dev/null
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+
+use Eval::Closure;
+
+{
+ my @keys_before = keys %::;
+
+ my $sub = eval_closure(
+ source => 'sub { 1 }',
+ description => 'foo',
+ );
+
+ is_deeply([sort keys %::], [sort @keys_before]);
+}
+
+{
+ my @keys_before = keys %::;
+
+ my $sub = eval_closure(
+ source => 'sub { 1 }',
+ line => 100,
+ );
+
+ is_deeply([sort keys %::], [sort @keys_before]);
+}
+
+{
+ my @keys_before = keys %::;
+
+ my $sub = eval_closure(
+ source => 'sub { 1 }',
+ description => 'foo',
+ line => 100,
+ );
+
+ is_deeply([sort keys %::], [sort @keys_before]);
+}
+
+{
+ my @keys_before = keys %::;
+
+ my $sub = eval_closure(
+ source => 'sub { 1 }',
+ description => __FILE__,
+ );
+
+ is_deeply([sort keys %::], [sort @keys_before]);
+}
+
+done_testing;