2 ms·
Perl has had this for a long time. Tagging a getter with ":lvalue" will make it assignable, even usable with the increment operator: pirl @> sub hats : lva
by arunix 6y ago
Perl has had this for a long time. Tagging a getter with ":lvalue" will make it assignable, even usable with the increment operator:
pirl @> sub hats : lvalue { my ($self) = @_; $self->{hats}; }
@var = ();
pirl @> $obj = bless {}
@var = (
bless( {}, 'Shell::Perl::sandbox' )
);
pirl @> $obj->hats
@var = (
undef
);
pirl @> $obj
@var = (
bless( {}, 'Shell::Perl::sandbox' )
);
pirl @> $obj->hats = 1
@var = (
1
);
pirl @> $obj
@var = (
bless( {
'hats' => 1
}, 'Shell::Perl::sandbox' )
);
pirl @> $obj->hats
@var = (
1
);
pirl @> $obj->hats++
@var = (
1
);
pirl @> $obj->hats
@var = (
2
);
pirl @>