in reply to Re: Re: Inheriting from Class::PObject
in thread Can't inherit subroutines - workaround?

looks like I'm on my own with a lovely opportunity to write a storable class from the top on my own

I think you'd be better off just patching Class::PObject to handle this situation.

Something like the following should do the trick:

sub Class::PObject::Template::__props { my $self = shift; my @isa = ref($self) || $self; while ( scalar @isa ) { my $target = shift @ISA; no strict 'refs'; if ( my $props = ${ $target . '::props' } ) { return $props; } else { push @isa, @{ $target . '::ISA' } } } }

Replies are listed 'Best First'.
Re: Re: Re: Re: Inheriting from Class::PObject
by andyf (Pilgrim) on May 10, 2004 at 00:58 UTC
    Updated - I've thought about it some more and realised I've actually had multiple errors.
    For a moment there I was stright into Template.pm with CTRL+V at the ready, but realised what you gave me is to 'patch' to overload __props and will do it from anywhere.
    :)
    Anyway, I've been saying
    myHuman->save();
    and not,
    $person->save();
    Using the class and not the instance had me scratching my head. For a moment I though I solved it, but no.
    About the patch. I guess it works, I can now call save on classes derived using ISA. But there are complications, I can't see any of the column values anymore, they are not in the namespace now.
    My thinking is that I will try and make a storable class, maybe looking at PObject is a nice place to start, or I might find something else approriate. Please don't feel I'm ungrateful about the patch, I'm amazed you hooked in so quickly - the truth is that I don't fully understand it, or the PObject code I'm working with, and working with code I don't fully know makes me uncomfortable. The PObject class is very nice as a plugin, I've tested it in production and its solid as a rock, but what I really want is actually quite simple, just a save() method for all my classes in the tree which will serialise the thing to disk and let me restore it later. I can see complications with using too powerful a tool for slightly the wrong job, and so I'm going to try some othert ideas for a while. Cheers,
    Andy.

      I have just uploaded Class-PObject-2.15_01, a beta release, to CPAN. Should become available soon. Let me know if it solves the problem.

      URL: http://search.cpan.org/dist/Class-PObject

      After applying the above patch suggested by simonm things should work the way intended. According to you it didn't? I'm currently "fix"ing this inheritance issue in Class::PObject and would like to hear from you before I relese the new revision to CPAN. Could you please e-mail me at sherzodr(AT)handalak.com