Tricky subclassing problem: Parent class method uses static value from child class

Discussion in 'Perl Misc' started by don.hosek@gmail.com, Sep 26, 2006.

  1. Guest

    I want to be able to do something along the lines of:

    package A;
    @ISA = ('B');
    use Class::Std;

    my $foo='this';

    package C;
    @ISA = ('B');
    use Class::Std;

    my $foo='this';

    package B;
    use Class::Std;

    sub method {
    do something with $foo
    }

    (obviously, there's a bit more to this, but I'm trying to abstract
    things as much as possible).

    But I can't seem to find anyway to make $bar->method(); see the
    appropriate value of $foo depending on whether $bar is an object of
    type A or C. Am I going to have to have a method (or AUTOMETHOD) to
    copy $foo into the B namespace when method is called? Or is there a
    more elegant way of handling this? [As a note, in actuality, I'm
    dealing with a %foo rather than a $foo].
    , Sep 26, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    9
    Views:
    517
    CBFalconer
    Apr 25, 2006
  2. Replies:
    0
    Views:
    353
  3. metal
    Replies:
    8
    Views:
    486
    Bruno Desthuilliers
    Oct 30, 2009
  4. Noel Dolan
    Replies:
    0
    Views:
    206
    Noel Dolan
    Jul 18, 2004
  5. Bitswapper
    Replies:
    5
    Views:
    110
    Prasad, Ramit
    Aug 27, 2013
Loading...

Share This Page