note
perl-diddler
Wait, wait, wait...'bless only once'...?? Um...I don't think so...
<p>
Each object's creation code must return a blessed reference to indicate that the returned 'object' is now part of that class (has been blessed into that class) -- meaning that the reference can be now called on any method in the new class.
<p>
W/o the blessing @ each level, you couldn't use the reference to call subclass methods, as it's not a pointer of any class (yet), until it's done being initialized into that class.
<p>
So something like 'cacheable' wouldn't be able to use the 'path' method of 'url' to derive a cacheable's path. Example:
<code>
package url
(methods:new 'host' 'path')
package url::cacheable
sub new {
$package=shift;
$up=new url(@_); # host & path passed in args
$up->path($cpath) if ($cpath=_canonical_path($up->path)) ne $path;
bless $up, $package;
}
</code>
So when $up comes back from 'new url', it's a ref to a url-blessed object and is used as such. But not until the path of the 'url'
object has been tested as (and possibly set to) '_canonical_path', is it suitable to be blessed as a 'cachceable' object.
<p>
Am I missing something?
859439
859442