Skip to content

Instantly share code, notes, and snippets.

@dakkar
Created July 11, 2019 16:35
Show Gist options
  • Save dakkar/2387faa2db919dcf828177773042c973 to your computer and use it in GitHub Desktop.
Save dakkar/2387faa2db919dcf828177773042c973 to your computer and use it in GitHub Desktop.
abusing perl5 subroutine signatures
#!/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