Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

merlyn (47)

AOL IM: realmerlyn (Add Buddy, Send Message)
Yahoo! ID: realmerlyn (Add User, Send Message)

See my home page [].

Journal of merlyn (47)

Saturday January 04, 2003
12:49 PM

changing the tied object

[ #9759 ]
Just had a discussion on IRC... thought I would write this down in case anyone else wants the conclusion.

Yes, you can indeed write to $_[0] inside one of the tie accessor callbacks (like STORE or FETCH), and change the underlying hidden tied action object.

For example, suppose you want to wrap Apache::Session, so that on first store or fetch, it does some init before becoming a real session object:

package My::Apache::Session;
  my $class = shift;
  bless [@_], $class; # remember real args
sub FETCH {
  ## DO NOT USE shift HERE
  $_[0] = Apache::Session->TIEHASH(@{$_[0]});
sub STORE {
  ## DO NOT USE shift HERE
  $_[0] = Apache::Session->TIEHASH(@{$_[0]});
  $_[0]->STORE($_[1], $_[2]);
sub my_initialization { ... }

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.