Acme-Cat-Schroedinger
view release on metacpan or search on metacpan
lib/Acme/Cat/Schroedinger.pm view on Meta::CPAN
sub new{
my $class = shift;
my %options = @_;
my $self = sub {
my $attr = shift;
my @caller = caller;
return sub {'meow'} unless $caller[0] eq __PACKAGE__;
my %attrs = (
'temperament' => 'cooperative', # cooperative | perverse | random
'kittens' => 'inherit', # inherit | default | random
'mutable' => '1', # 0 | 1 # never usable
%options
);
return $attrs{$attr} if exists $attrs{$attr}; # check caller
my $coopRef = ($attrs{temperament} eq 'cooperative' or ($attrs{temperament} eq 'random' and int(rand(2)) ) )? undef:'';
my %overload = (
'0+' => sub {return ($_[0]= defined $coopRef?die:0);},
'""' => sub {return ($_[0]= defined $coopRef?die:'');}, # todo: include temperament
'@{}' => sub {return ($_[0]=$coopRef // []);}, # todo: include temperament
'%{}' => sub {return ($_[0]=$coopRef // {});}, # todo: include temperament
( run in 0.663 second using v1.01-cache-2.11-cpan-8780591d54d )