jcupp has asked for the wisdom of the Perl Monks concerning the following question:

MoNkS- Is this a good thing? I see it as (yet another) way to separate data from the implementation. Or a sneaky way to pass the tied Apache session hash (from Apache::Session) as as reference to another class -- the $self in every method of that class... Would you ever bless a tied variable into the same tied class? Mmmm...

Replies are listed 'Best First'.
Re: Blessing a Tied something?
by IlyaM (Parson) on Apr 01, 2002 at 09:13 UTC
    Would you ever bless a tied variable into the same tied class?

    I guess you meant bless a reference on tied variable into the same tied class.

    Do not do it unless you are going to post you code into Obfuscated Code section of PerlMonks. Tied variable already has underlaying object. If you bless reference on tied variable you get another object. For these two objects you will have some methods. If these two objects are going to share same package you will have to put methods for two different classes of objects into one package. It is not something I would recomend to do if you want to write clean, easy to understand code.

    On the other hand blessing a reference on tied variable into separate package maybe ok. One good example is Tie::SecureHash. References on variables tied into this package are supposed to be blessed into other packages.

    --
    Ilya Martynov (http://martynov.org/)

Re: Blessing a Tied something?
by Juerd (Abbot) on Apr 01, 2002 at 11:59 UTC

    Would you ever bless a tied variable into the same tied class? Mmmm...

    Not into the same class, but I don't feel bad about passing a reference to a tied hash or array to another tie call, as this allows for using two modules together: See Re: How do I insert a line into a file?.

    U28geW91IGNhbiBhbGwgcm90MTMgY
    W5kIHBhY2soKS4gQnV0IGRvIHlvdS
    ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
    geW91IHNlZSBpdD8gIC0tIEp1ZXJk
    

Re: Blessing a Tied something?
by theorbtwo (Prior) on Apr 01, 2002 at 18:45 UTC

    If you're thinking of doing this, read Object Oriented Perl, by Damien Conway.


    We are using here a powerful strategy of synthesis: wishful thinking. -- The Wizard Book