use strict;
use warnings;
+use Try::Tiny;
+
our $VERSION = '1.19';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
( ref $self && $self->associated_attribute ) || $self->SUPER::_error_thrower();
}
-sub _eval_code {
- my ( $self, $source ) = @_;
-
- my $environment = $self->_eval_environment;
-
- my ( $code, $e ) = $self->_compile_code( environment => $environment, code => $source );
-
- $self->throw_error(
- "Could not create writer for '${\$self->associated_attribute->name}' because $e \n code: $source",
- error => $e, data => $source )
- if $e;
-
- return $code;
+sub _compile_code {
+ my $self = shift;
+ my @args = @_;
+ try {
+ $self->SUPER::_compile_code(@args);
+ }
+ catch {
+ $self->throw_error(
+ 'Could not create writer for '
+ . "'" . $self->associated_attribute->name . "' "
+ . 'because ' . $_,
+ error => $_,
+ );
+ };
}
sub _eval_environment {
my $inv = '$_[0]';
my $value_name = $self->_value_needs_copy ? '$val' : '$_[1]';
- $self->_eval_code('sub { ' . "\n"
+ $self->_compile_code('sub { ' . "\n"
. $self->_inline_pre_body(@_) . "\n"
. 'if (scalar(@_) >= 2) {' . "\n"
. $self->_inline_copy_value . "\n"
my $inv = '$_[0]';
my $value_name = $self->_value_needs_copy ? '$val' : '$_[1]';
- $self->_eval_code('sub { '
+ $self->_compile_code('sub { '
. $self->_inline_pre_body(@_)
. $self->_inline_copy_value
. $self->_inline_check_required
my $inv = '$_[0]';
my $slot_access = $self->_inline_get($inv);
- $self->_eval_code('sub {'
+ $self->_compile_code('sub {'
. $self->_inline_pre_body(@_)
. $self->_inline_throw_error('"Cannot assign a value to a read-only accessor"', 'data => \@_') . ' if @_ > 1;'
. $self->_inline_check_lazy($inv)
use Carp ();
use Scalar::Util 'blessed', 'weaken', 'looks_like_number', 'refaddr';
+use Try::Tiny;
our $VERSION = '1.19';
our $AUTHORITY = 'cpan:STEVAN';
my $defaults = [map { $_->default } @$attrs];
- my ( $code, $e ) = $self->_compile_code(
- code => $source,
- environment => {
- '$meta' => \$self,
- '$attrs' => \$attrs,
- '$defaults' => \$defaults,
- '@type_constraints' => \@type_constraints,
- '@type_constraint_bodies' => \@type_constraint_bodies,
- },
- );
-
- $self->throw_error(
- "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$e",
- error => $e, data => $source )
- if $e;
+ my $code = try {
+ $self->_compile_code(
+ source => $source,
+ environment => {
+ '$meta' => \$self,
+ '$attrs' => \$attrs,
+ '$defaults' => \$defaults,
+ '@type_constraints' => \@type_constraints,
+ '@type_constraint_bodies' => \@type_constraint_bodies,
+ },
+ );
+ }
+ catch {
+ $self->throw_error(
+ "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$_",
+ error => $_,
+ data => $source,
+ );
+ };
$self->{'body'} = $code;
}
use Devel::GlobalDestruction ();
use Scalar::Util 'blessed', 'weaken';
-use Try::Tiny ();
+use Try::Tiny;
our $VERSION = '1.19';
$VERSION = eval $VERSION;
warn $source if $self->options->{debug};
- my ( $code, $e ) = $self->_compile_code(
- environment => {},
- code => $source,
- );
-
- $self->throw_error(
- "Could not eval the destructor :\n\n$source\n\nbecause :\n\n$e",
- error => $e, data => $source )
- if $e;
+ my $code = try {
+ $self->_compile_code(source => $source);
+ }
+ catch {
+ $self->throw_error(
+ "Could not eval the destructor :\n\n$source\n\nbecause :\n\n$_",
+ error => $_,
+ data => $source,
+ );
+ };
$self->{'body'} = $code;
}