Skip to content

Instantly share code, notes, and snippets.

@ap
Last active November 1, 2020 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ap/de85241b45fce641fbdc793bff17e009 to your computer and use it in GitHub Desktop.
Save ap/de85241b45fce641fbdc793bff17e009 to your computer and use it in GitHub Desktop.
Wantarray::Horrible
package Wantarray::Horrible;
sub new {
my ( $class, $wantarray, $sub ) = ( shift, shift, shift );
; $wantarray ? bless [ &$sub ], __PACKAGE__.'::List'
: defined $wantarray ? bless \( scalar &$sub ), __PACKAGE__.'::Sclr'
: bless \do { &$sub; my $o }, __PACKAGE__.'::Void';
}
sub Wantarray::Horrible::List::value { @{ $_[0] } }
sub Wantarray::Horrible::Sclr::value { ${ $_[0] } }
sub Wantarray::Horrible::Void::value { () }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment