Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^4: perl inheritance

by Anonymous Monk
on Mar 26, 2012 at 14:07 UTC ( [id://961670]=note: print w/replies, xml ) Need Help??


in reply to Re^3: perl inheritance
in thread perl inheritance

My sincere apologies for replying to you so late, Chromatic. Unfortunately, I don't have decent code worth posting at this point. Would you possibly have any example classes that you can point me to that would demonstrate what you are referring to..

many thanks as usual. Michael

Replies are listed 'Best First'.
Re^5: perl inheritance
by chromatic (Archbishop) on Mar 27, 2012 at 16:19 UTC

    Assuming your constructor, new, can create new objects when given the appropriate arguments:

    package ReblessKids; use strict; use warnings; use Scalar::Util 'blessed'; sub do_something { my $self = shift; ... my $class = blessed $self; return $class->new( ... ); }

    Update: I did mean blessed, not reftype.

      $class = reftype $self
      This seems to be return 'HASH' and not the subclass. What am I doing wrong?
      in other words, I'm getting the following error when I try to call $class->new(...)
      Can't locate object method "new" via package "HASH" (perhaps you forgo +t to load "HASH"?) at Table.pm line 34. at Table.pm line 34
      I thought that reftype would return the polymorphic type (i.e. the subclass). Sorry Chromatic, but I'm bit confused here..
        Yes, reftype() returns the type of the variable. I think what was meant was blessed() which returns the name of the package that it is blessed into:
        my $class = blessed $self;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-18 05:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found