http://qs321.pair.com?node_id=859439

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):

package URL; {... sub new { my $package=shift; my $argsp = $_[0]; my $up= { host => '', path => '', }; foreach (keys %$up, @arg_aliases) { $up->{$compose_argmap{_tl( $_)}}=$argsp->{$_} if exists $argsp-> +{$_}; } bless $up, $package; } }
in derived classes, the 'new' looks like:
package URL::Storable; { our @ISA=qw(URL); sub new { my $package=shift; my $argsp = $_[0]; # setting a "per-class" var, not per-instance if (exists $argsp->{save_prefix}) { $save_prefix=$argsp->{save_prefix}; } my $this=new URL(@_); # (process this packages args....) bless $this, $package; #bless and return } }
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...
thanks... (Note, fixed example typo resulting from starting with a demo case, then copying in actual code (re: $up (in code for url pointer), vs. $url used in demo case).