Will we have lvalue methods in Perl 6? Because that's what really bugs me, about Perl 5 OO.
$obj->SetProperty("something");
is just ugly, compared to the shiny elegance of
$obj->Property = "something";
| [reply] [d/l] [select] |
You bet you will have them! Only such a method will be spelled 'is rw'. Well, until Larry changes his mind on this...
| [reply] [d/l] |
use v6;
class test {
has $.Property;
}
my $testing = new test;
$testing.Property = 5;
$testing.Property.say;
I beleive that it actualy uses a Proxy object with lvalue attributes, but don't quote me on that. ;)
| [reply] [d/l] |
Gah, ambiguous indirect object notation went away in Perl 6. Mark the invocant explicitly:
my $testing = new test:;
Or make a method call look like a method call:
my $testing = test.new()
| [reply] [d/l] [select] |
package Foo;
sub foo : lvalue {
my $self = shift;
warn "Only first argument to method foo is used" if @_ > 1;
$self->{ foo } = shift if @_;
$self->{ foo };
}
my $x = bless +{}, 'Foo';
$x->foo = 3;
print $x->foo, "\n";
$x->foo++;
print $x->foo, "\n";
$x->foo += 6;
print $x->foo, "\n";
__END__
3
4
10
I know that user-defined functions with the lvalue attribute, in general, will give wrong results in the debugger, but that's only a problem for those weenies who use the debugger ;-) (Plus, there are good ways around this.)
| [reply] [d/l] |
Yeah. The problem with them is one can't check the value before it is set. I would like to have something like
sub foo : get
{
my $self = shift;
return $self->{_foo};
}
sub foo : set
{
my $self = shift;
my $value = shift;
die "foo is a integer field!\n"
unless $value =~ /[+-]?[0-9]+/;
$self->{_foo} = $value;
}
| [reply] [d/l] |