Skip to content

Instantly share code, notes, and snippets.

@arunbear
Created December 26, 2020 16:39
Show Gist options
  • Save arunbear/12d830f422650c7151652c359d5d2805 to your computer and use it in GitHub Desktop.
Save arunbear/12d830f422650c7151652c359d5d2805 to your computer and use it in GitHub Desktop.
lvalue methods in Perl
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 @>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment