From: Chris W. <ch...@cw...> - 2004-01-06 18:27:22
|
On Jan 6, 2004, at 11:32 AM, Vsevolod (Simon) Ilyushchenko wrote: >> Okay, I've got a test script + classes that has this setup with >> strict field checking and field autodiscovery. > > Sorry, no script was attached. :( Dratted mailing list managers! Try: http://www.cwinters.com/raw/book_sample.tar.gz >>> 1. My classes have a superclass. Let's call it MyObject. So I >>> inherit MyBooks from SPOPS_Books and MyObject. I have to >>> double-dispatch the new() method, but I can live with it. >> This might be a problem. How are you dispatching new()? > > Nothing fancy - in MyObject: > sub new > { > my ($proto) = shift; > my %args = %{$_[0]}; > > my $self = $proto->SUPER::new(@_); > $self->_new(\%args); > > return $self; > } > > MyObject inherits from ProtoObject, which is a parent also to > non-SPOPS classes. In ProtoObject, _new() calls $self->new(), and > everybody's happy. Since only one ugly method was introduced, this is > not a big deal. Ugh, that blows. I'm going to introduce a initialize_custom() method to SPOPS.pm which you can override to do whatever you want. This is a very useful feature and I can't believe it's not there already. > Thanks - that helped my script to compile! However, when I added > another line: > Job->fetch(1) > I got this: > > Can't locate package SPOPS_Job for @Job::ISA at script.pl line 5. > Can't locate package SPOPS_Job for @Job::ISA at script.pl line 6. > Can't locate package SPOPS_Job for @Job::ISA at script.pl line 6. > Can't locate object method "fetch" via package "Job" at script.pl line > 6. You still need to initialize your SPOPS classes before trying to use 'Job'. See the tarball above for my example. Chris -- Chris Winters Creating enterprise-capable snack systems since 1988 |