|There's more than one way to do things|
blessed confusionby perl-diddler (Hermit)
|on Sep 08, 2010 at 22:52 UTC||Need Help??|
perl-diddler has asked for the
wisdom of the Perl Monks concerning the following question:
Just when I thought I had some clue about how things work, I go and run into problems, proving that I'm overlooking the obvious or not remembering as well as I thought I did...
I have (what I thought) was a fairly straight forward set of classes that are all subclasses of the one above (no multiple inheritance issues at this point).
I'm storing data object data in a blessed hash that's created in the most 'base' class's 'new' routine. That's blessed in the base class and returned 'up' the call stack to the successive, derived-class, 'new' routines, where they may add their own data (as more hash entries in the same hash). They then bless and return the has w/any new entries to the next class in line.
So classes 'URL' => URL::Storable => URL::Fetchable are subclasses in that order from least specific to 'derived'.
In URL, code looks like (abbreviated):
in derived classes, the 'new' looks like:
And so on... If the above is the 1st derived class, then on the 2nd derived class (derived from the 1st derived class, not the base class of the 1st), gets an error when I try to bless it:
Attempt to bless into a reference at filename.pl line xxx.
Is what I am doing, reasonable for a smallish project (at this point, its all in 1 file). If it is, then is there common 'gotcha', that would cause this?
Isn't this 'a' normal way of doing classing with each level plugging in it's local-object data, then blessing it at the current class level, and returning it. Then any call on an object would (in theory), go from the most derived object look in it's "ISA" for the next, and go to the next level?
If this all seems straightforward so far, and nothing looks amiss, I can start more wholesale copying of code into this question, but I didn't want to go into unnecessary detail for something that seems pretty straight forward, where I'm feeling I must be overlooking something obvious OR have some basic misunderstanding about how things work somewhere, but since the code 'look's fairly simple, I'm checking my understanding first, since I'm not sure why, for example, it would fail when I bless in the 2nd level derivation class, as opposed to in the first-level derivation class, where I'm first blessing that returned 'object' from the base class, URL, after having added an arg to it.
Ideas or 'clue-sticks' welcomed...