Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Re: How can I unbless an object?

by mp (Deacon)
on Jul 19, 2002 at 18:28 UTC ( [id://183359]=note: print w/replies, xml ) Need Help??


in reply to Re: How can I unbless an object?
in thread How can I unbless an object?

What you suggest works and is basically what I'm currently doing, but I would prefer not to have to waste resources to copy the hash just to get a non-blessed copy of it, especially when the particular application of this can end up making a copy of some fairly large hash of array of hash of ... - type structures.

Update: changed wording slightly.

Replies are listed 'Best First'.
Re: Re: Re: How can I unbless an object?
by vladb (Vicar) on Jul 19, 2002 at 20:08 UTC
    Please see my updated post above.

    Also, looking at your particular application of this, I can't quite understand why do you need to worry much about blessed entities (structures). No matter what 'class' name your hash structure has been branded with, in the end you still deal with the same hash structure. The $self variable is simply referencing that 'named' structure. And when you do $self->method(), Perl simply interprets it as FOO::method($self) on the basis that '$self' has been 'labeled' as belonging to the package or being of type 'FOO'. That's all. Nontheless, I can still do this:
    package FOO; sub new { bless { key1 => 1, key2 => 2 }; } package main; my $foo = new FOO(); print "Look, first key = '$foo->{key1}'!\n";
    Output:
    Look, first key = '1'!
    Clearly, that $foo object is nothing but a reference to a hash. Simple as that.

    _____________________
    # Under Construction
      That works for normal perl, but not for templates in Template Toolkit (TT2), which is what the attempted unblessed object is for use with. TT2 uses a "dot" (.) notation rather than normal perl syntax, then tries to figure out what to do based on the type (I think it just looks at ref($whatever), but I am not very familiar its inner workings) when it compiles the template.

      When you say something like [% d.e.f %], TT2 will actually use $d->e->f or $d->e->{f} or $d->{e}->{f}, etc., depending on what $d and $d->e (or $d->{e}, etc.) really is. This is the DWIM behavior that Randall referred to above.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://183359]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-19 04:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found