Skip to content

Instantly share code, notes, and snippets.

@dr-kd
Created August 8, 2023 23:59
Show Gist options
  • Save dr-kd/a8aecbb89ef0abd891909d0246db7fd8 to your computer and use it in GitHub Desktop.
Save dr-kd/a8aecbb89ef0abd891909d0246db7fd8 to your computer and use it in GitHub Desktop.
# Before:
my %thing = ( this => 'that', other => $self->my_method(@args));
sub my_method { ...; return $stuff }
# except it's really easy for me the developer to forget to type the 'other' key
# which results in surprising fails
# So ... wantarray
my $thing = (this => 'that', $self->my_method);
sub my_method { ...; return wantarray ? ( other => $stuff ) : $stuff };
# and no more surprises
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment