Acme-Cat-Schroedinger

 view release on metacpan or  search on metacpan

lib/Acme/Cat/Schroedinger.pm  view on Meta::CPAN

		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
			'${}' => sub {return ($_[0]=$coopRef // \0);}, # todo: include temperament
			'*{}' => sub {return ($_[0]=$coopRef // \*{''});}, # todo: include temperament
		);
		return $overload{$attr};
	};



( run in 2.032 seconds using v1.01-cache-2.11-cpan-d80b1682f3f )