Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: Re: Re: Re: Are array based objects fixed length?

by Felonious (Chaplain)
on Jul 28, 2002 at 20:53 UTC ( #185848=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Re: Re: Are array based objects fixed length?
in thread Are array based objects fixed length?

Trouble is, we only want to override DESTROY for objects that have been fetched from or stored with Pixie

The code below reblesses the object into a new class that is based on it's existing class, establishing the necessary ISA relationships to make it work like before, yet call your DESTROY method.

package Pixie::objwrapper; sub wrap { my $class = shift; my $obj = shift; my $obj_class = ref($obj); { no strict; @{"Pixie::objwrapper::${obj_class}::ISA"} = ('Pixie::o +bjwrapper', $obj_class); } return bless $obj, "Pixie::objwrapper::$obj_class"; } sub DESTROY { my $self = shift; print "wrapper->DESTROY\n"; my $obj_class = ref($self); $obj_class =~ s/Pixie::objwrapper:://; if ($obj_class->can('DESTROY')) { $obj_class->DESTROY($self); } }
UPDATE: Fixed some code that was uglier than necessary.

-- O thievish Night, Why should'st thou, but for some felonious end, In thy dark lantern thus close up the stars? --Milton


Comment on Re: Re: Re: Re: Re: Are array based objects fixed length?
Download Code
Re: Re: Re: Re: Re: Re: Are array based objects fixed length?
by pdcawley (Hermit) on Jul 29, 2002 at 11:42 UTC
    Oh yes, of course. Because we're going to want this behaviour for every Pixie managed object of the class then all instances of that class can share the 'shadow' Pixie class. Thanks for that.

    BTW, your DESTROY still looks a bit wrong. Should probably be:

    sub DESTROY { my $self = shift; print "wrapper->DESTROY\n"; my $obj_class = ref($self); $obj_class =~ s/Pixie::objwrapper:://; if ( my $method = $obj_class->can('DESTROY') ) { $method->($self); } }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2014-08-01 07:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (257 votes), past polls