Re: lvaluable AUTOLOAD (help! Abigail! someone!)



Dodger wrote:

So it seemed that with all the things Perl can do I should have been
able to do the same thing in Perl, right? Maybe with a little
finagling, but it hsould be possible.

Take a look at Contextual::Return. It may provide enough syntactical sugar
to make this easy.

Rough guess, untested:

sub _any(&@) { my $s = shift; $s->() && return 1 for @_; return; }
sub AUTOLOAD :lvalue {
my $self = shift;
my ($property) = $AUTOLOAD) =~ /::([^:]+)$/;

if (_any { $property eq $_ }, @{$self->{_vars}{protected}}) {
return RVALUE { $self->{$property} }
LVALUE { require Carp; croak "Can't use $property as lvalue" }
}
$self->{$property}
}

Or something like that.
.