L<Moose> overrides the description for accessors to something like "accessor
foo at MyClass.pm, line 123").
+=item line
+
+This lets you override the particular line number that appears in backtraces,
+much like the description option. The default is "1".
+
=item terse_error
Normally, this function appends the source code that failed to compile, and
$args{source} = _canonicalize_source($args{source});
_validate_env($args{environment} ||= {});
- $args{source} = _line_directive($args{description}) . $args{source}
+ $args{source} = _line_directive(@args{qw(line description)}) . $args{source}
if defined $args{description};
my ($code, $e) = _clean_eval_closure(@args{qw(source environment)});
}
sub _line_directive {
- my ($description) = @_;
+ my ($line, $description) = @_;
+
+ $line = 1 if !defined($line);
- return qq{#line 1 "$description"\n};
+ return qq{#line $line "$description"\n};
}
sub _clean_eval_closure {
);
}
+{
+ my $code = eval_closure(
+ source => $source,
+ line => 100,
+ description => 'accessor foo (defined at Class.pm line 282)',
+ );
+
+ like(
+ exception { $code->() },
+ qr/^foo at accessor foo \(defined at Class\.pm line 282\) line 101\n/,
+ "description is set"
+ );
+}
done_testing;