Skip to content

Instantly share code, notes, and snippets.

@kentaro
Created August 24, 2011 10:21
Show Gist options
  • Save kentaro/1167734 to your computer and use it in GitHub Desktop.
Save kentaro/1167734 to your computer and use it in GitHub Desktop.
Semantic False Class
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