in reply to using TIEHASH as wrapper/proxy, while avoiding recursion and warnings

Do you really have to wrap / rebless an existing object or can you just create a fresh object that is tied/overloaded/whatever that uses AUTOLOAD to redirect the accesses and method calls to the "original" object?

Otherwise, I see very little beyond reblessing/re-tieing.

  • Comment on Re: using TIEHASH as wrapper/proxy, while avoiding recursion and warnings
  • Download Code

Replies are listed 'Best First'.
Re^2: using TIEHASH as wrapper/proxy, while avoiding recursion and warnings
by LanX (Saint) on Apr 21, 2024 at 18:35 UTC
    In my use-case I could actually replace the variable's ref in the functions pad with a new one.

    But in general tie %var is supposed to dock to an existing variable without changing it's name or reference!

    That's why the pedant in me is surprised that I have to jump thru all those hoops.

    And yes I tried to not reinvent the wheel and found Tie::Watch , what they do is actually a flat copy of the whole data-structure in the constructor.

      -shadow (default 1) is 0 to disable array and hash shadowing. To prevent infinite recursion Tie::Watch maintains parallel variables for arrays and hashes. When the watchpoint is created the parallel shadow variable is initialized with the watched variable's contents, and when the watchpoint is deleted the shadow variable is copied to the original variable. Thus, changes made during the watch process are not lost. Shadowing is on my default. If you disable shadowing any changes made to an array or hash are lost when the watchpoint is deleted.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery