Created
July 11, 2019 16:35
-
-
Save dakkar/2387faa2db919dcf828177773042c973 to your computer and use it in GitHub Desktop.
abusing perl5 subroutine signatures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use 5.024; | |
use strict; | |
use warnings; | |
use experimental 'signatures'; | |
package Foo { | |
sub new($class,%attrs) { bless \%attrs,$class } | |
sub thing($self,$value=return $self->{thing}) { $self->{thing} = $value } | |
}; | |
my $foo = Foo->new(thing=>7); | |
say $foo->thing; # prints 7 | |
$foo->thing(5); | |
say $foo->thing; # prints 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment