#!/usr/local/bin/perl #!/usr/bin/perl use 5.010; use strict; use warnings; { package FlipFlop; use overload 'bool' => \&fetch, '0+' => \&numify, '""' => \&numify ; sub new { my $class = shift; my $self = !shift; bless \$self, $class; } sub fetch { my $self = shift; $$self = !$$self; } sub numify { shift->fetch + 0; } } my $fl = new FlipFlop; say $fl; say $fl; say $fl; say $fl;