The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Tie::Indirect::* -- tie variables to access data located at run-time.

DESCRIPTION

  Each tied variable accesses data located by calling a sub
  which returns a reference to the data.  
 
  The sub is called with parameters ($mutating, optional tie args...)
  where $mutating is true if the access may modify the value. 
 
  tie $scalar, 'Tie::Indirect::Scalar', \&sub, optional tie args...
  tie @array,  'Tie::Indirect::Array',  \&sub, optional tie args...
  tie %hash,   'Tie::Indirect::Hash',   \&sub, optional tie args...
 
  EXAMPLE:
    my $dataset1 = { foo=>123, table=>{...something...}, list=>[...] };
    my $dataset2 = { foo=>456, table=>{...something else...}, list=>[...] };
 
    my $masterref;
 
    our ($foo, %table, @list);
    tie $foo,   'Tie::Indirect::Scalar', sub{ \$masterref->{$_[1]} }, 'foo';
    tie %table, 'Tie::Indirect::Hash',   sub{ $masterref->{$_[1]} }, 'table; 
    tie @list,  'Tie::Indirect::Array',  sub{ $masterref->{list} };
 
    $masterref = $dataset1;
    ... $foo, %table, and @list now access members of $dataset1
    $masterref = $dataset2;
    ... $foo, %table, and @list now access members of $dataset2
 

AUTHOR / LICENSE

Jim Avera (jim.avera AT gmail) / Public Domain or CC0