Created
August 24, 2011 10:21
-
-
Save kentaro/1167734 to your computer and use it in GitHub Desktop.
Semantic False Class
This file contains hidden or 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 main; | |
use strict; | |
use warnings; | |
package SemanticFalse; | |
use strict; | |
use warnings; | |
use overload bool => sub { | |
my $self = shift; | |
if ($$self eq 'false') { | |
return 0; | |
} | |
!!$$self; | |
}; | |
sub new { | |
my ($class, $string) = @_; | |
$string ||= ''; | |
bless \$string, $class; | |
} | |
package main; | |
use Test::More; | |
my $true = SemanticFalse->new('true'); | |
my $false = SemanticFalse->new('false'); | |
ok $true; | |
ok !$false; | |
done_testing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment