use Carp 'confess';
use Scalar::Util 'blessed', 'weaken';
+use Try::Tiny;
-our $VERSION = '1.08';
+our $VERSION = '1.11';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
my $self = shift;
my $attr = $self->associated_attribute;
- my ( $code, $e ) = $self->_eval_closure(
- {},
- 'sub {'
- . $attr->inline_set( '$_[0]', '$_[1]' )
- . ' if scalar(@_) == 2; '
- . $attr->inline_get('$_[0]') . '}'
- );
- confess "Could not generate inline accessor because : $e" if $e;
+ my $code = try {
+ $self->_compile_code([
+ 'sub {',
+ $attr->inline_set('$_[0]', '$_[1]'),
+ 'if scalar(@_) == 2;',
+ $attr->inline_get('$_[0]') . ';',
+ '}',
+ ]);
+ }
+ catch {
+ confess "Could not generate inline accessor because : $_";
+ };
return $code;
}
my $self = shift;
my $attr = $self->associated_attribute;
- my ( $code, $e ) = $self->_eval_closure(
- {},
- 'sub {'
- . 'confess "Cannot assign a value to a read-only accessor" if @_ > 1;'
- . $attr->inline_get('$_[0]') . '}'
- );
- confess "Could not generate inline reader because : $e" if $e;
+ my $code = try {
+ $self->_compile_code([
+ 'sub {',
+ 'confess "Cannot assign a value to a read-only accessor"',
+ 'if @_ > 1;',
+ $attr->inline_get('$_[0]') . ';',
+ '}',
+ ]);
+ }
+ catch {
+ confess "Could not generate inline reader because : $_";
+ };
return $code;
}
my $self = shift;
my $attr = $self->associated_attribute;
- my ( $code, $e ) = $self->_eval_closure(
- {},
- 'sub {' . $attr->inline_set( '$_[0]', '$_[1]' ) . '}'
- );
- confess "Could not generate inline writer because : $e" if $e;
+ my $code = try {
+ $self->_compile_code([
+ 'sub {',
+ $attr->inline_set('$_[0]', '$_[1]') . ';',
+ '}',
+ ]);
+ }
+ catch {
+ confess "Could not generate inline writer because : $_";
+ };
return $code;
}
my $self = shift;
my $attr = $self->associated_attribute;
- my ( $code, $e ) = $self->_eval_closure(
- {},
- 'sub {' . $attr->inline_has('$_[0]') . '}'
- );
- confess "Could not generate inline predicate because : $e" if $e;
+ my $code = try {
+ $self->_compile_code([
+ 'sub {',
+ $attr->inline_has('$_[0]') . ';',
+ '}',
+ ]);
+ }
+ catch {
+ confess "Could not generate inline predicate because : $_";
+ };
return $code;
}
my $self = shift;
my $attr = $self->associated_attribute;
- my ( $code, $e ) = $self->_eval_closure(
- {},
- 'sub {' . $attr->inline_clear('$_[0]') . '}'
- );
- confess "Could not generate inline clearer because : $e" if $e;
+ my $code = try {
+ $self->_compile_code([
+ 'sub {',
+ $attr->inline_clear('$_[0]') . ';',
+ '}',
+ ]);
+ }
+ catch {
+ confess "Could not generate inline clearer because : $_";
+ };
return $code;
}
=head1 DESCRIPTION
-This is a subclass of <Class::MOP::Method> which is used by
+This is a subclass of C<Class::MOP::Method> which is used by
C<Class::MOP::Attribute> to generate accessor code. It handles
generation of readers, writers, predicates and clearers. For each type
of method, it can either create a subroutine reference, or actually