my $meta_instance = $attr->associated_class->instance_metaclass;
my $code = $self->_eval_closure(
- q{},
+ {},
'sub {'
. $meta_instance->inline_set_slot_value('$_[0]', "'$attr_name'", '$_[1]')
. ' if scalar(@_) == 2; '
my $meta_instance = $attr->associated_class->instance_metaclass;
my $code = $self->_eval_closure(
- q{},
+ {},
'sub {'
. 'confess "Cannot assign a value to a read-only accessor" if @_ > 1;'
. $meta_instance->inline_get_slot_value('$_[0]', "'$attr_name'")
my $meta_instance = $attr->associated_class->instance_metaclass;
my $code = $self->_eval_closure(
- q{},
+ {},
'sub {'
. $meta_instance->inline_set_slot_value('$_[0]', "'$attr_name'", '$_[1]')
. '}'
my $meta_instance = $attr->associated_class->instance_metaclass;
my $code = $self->_eval_closure(
- q{},
+ {},
'sub {'
. $meta_instance->inline_is_slot_initialized('$_[0]', "'$attr_name'")
. '}'
my $meta_instance = $attr->associated_class->instance_metaclass;
my $code = $self->_eval_closure(
- q{},
+ {},
'sub {'
. $meta_instance->inline_deinitialize_slot('$_[0]', "'$attr_name'")
. '}'
sub generate_constructor_method_inline {
my $self = shift;
+ my $close_over = {};
+
my $source = 'sub {';
$source .= "\n" . 'my $class = shift;';
# to be picked up in the eval
$code = $self->_eval_closure(
- q{my $attrs = $self->attributes;},
+ { '$attrs' => \$self->attributes },
$source
);
confess "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$@" if $@;
}
sub _eval_closure {
- my $self = shift;
- eval join("\n",@_);
+ # my ($self, $captures, $sub_body) = @_;
+ my $__captures = $_[1];
+ eval join(
+ "\n",
+ (map {
+ /^([\@\%\$])/
+ or die "capture key should start with \@, \% or \$: $_";
+ q!my !.$_.q! = !.$1.q!{$__captures->{'!.$_.q!'}};!;
+ } keys %$__captures),
+ $_[2]
+ );
}
1;