Last active
September 30, 2016 11:48
-
-
Save jhthorsen/6a00f9cb50d4e21c5dcd58d94925774b to your computer and use it in GitHub Desktop.
This is stupid, but I made it anyway
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
package void; | |
use strict; | |
use Exporter 'import'; | |
use Carp; | |
our @EXPORT = 'void'; | |
sub void { | |
return unless defined wantarray; | |
my $caller = (caller 1)[3]; | |
Carp::croak("$caller() is designed for void context"); | |
} | |
return 1 if defined wantarray; | |
# perl ./void.pm | |
require Test::More; | |
my $manipulate = sub { | |
$_[0]->{foo} = 123; | |
return void; | |
}; | |
eval { $manipulate->({}) }; | |
Test::More::ok(!$@, 'void context') or Test::More::diag($@); | |
my $x = eval { $manipulate->({}) }; | |
Test::More::like($@, qr{void::__ANON__\(\) is designed for void}, 'not void context'); | |
Test::More::done_testing(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment