Cac::Bind - Bind unindexed local COS variables to %C


Cac documentation Contained in the Cac distribution.

Index


Code Index:

NAME

Top

Cac::Bind - Bind unindexed local COS variables to %C

SYNOPSIS

Top

  use Cac::Bind;
  $C{a} = 1;      # s a=1
  delete $C{a};   # k a
  print $C{a};    # fetches value of "a"

DESCRIPTION

Top

 Cac::Bind just binds all unindexed local variables
 to the Perl-Hash %C.

 This is the easy way to set/get local COS variables
 if you need to do so.

EXPORTS

Top

%C
 The hash. :)

SEE ALSO

Top

Cac, Cac::ObjectScript, Cac::Global, Cac::Routine, Cac::Util.

AUTHOR

Top

 Stefan Traby <stefan@hello-penguin.com>
 http://hello-penguin.com


Cac documentation Contained in the Cac distribution.

package Cac::Bind;

use 5.007;
use strict;
use warnings;

require Exporter;
use AutoLoader qw(AUTOLOAD);

our @ISA = qw(Exporter);

our @EXPORT_OK = qw( %C );
our @EXPORT = @EXPORT_OK;

our $VERSION = 1.83;

use Cac::ObjectScript;

our %C;
our $unused;

sub STORE {
   my (undef, $key, $val) = @_;
   ref $val and die "expected scalar";
   <:S @:key = :val:> 
   $key;
}

our $cookie = "94d73bc836e5b1612d4cab97ad49c501";

sub FETCH {
   my $key = $_[1];
   my $val = <? $get(@:key, :cookie):>;
   undef $val if $val eq $cookie;
   $val
}

sub DESTROY {
   # doing bad things here in the near future :)
}


# delete returns the value before deleting, at least I care...
sub DELETE {
   my $key = $_[1];
   my $oval = <? $get(@:key , :cookie):>;
   <:K @:key:>
   undef $oval if $oval eq $cookie;
   $oval;
}

sub EXISTS {
   my $key = $_[1];
   my $val = <? $get(@:key , :cookie):>;
   !($val eq $cookie);
}


sub TIEHASH {
   bless \$unused, $_[0];
}

tie %C, __PACKAGE__;


1;
__END__