On Fri, 30 Apr 2004, Aldo Calpini wrote:

> let's suppose I want to build a class that keeps track of the objects it
> creates.
>
> let's suppose that I want this class to be the base for a variety of
> classes.
>
> let's suppose that I decide, rather than fiddling with the default
> constructor, to wrap it up.
>
> something like:
>
>     class Animal {
>         our @.zoo;
>         &new.wrap( {
>             my @results = call();
>             push(@.zoo, @results[0]);
>             return @results;
>         } );
>     }
>     class Lion is Animal { ... }
>     class Tiger is Animal { ... }
>     class Panther is Animal { ... }
>
>     my $simba = Lion.new();
>     my $shere_khan = Tiger.new();
>     my $bagheera = Panther.new();
>
>     my @all = @Animal::zoo;
>     # @all should contain ($simba, $shere_khan, $bagheera);
>
> will the above code work as expected, or is there something I've
> overlooked?

For this particular case, I guess wrapping the BUILD submethod of Animal
would work as it will surely get called. Moreover, since it will be called
by BUILDALL in its own class the wrapper will work, regardless of how
wrappers get inherited.

But I suppose you were asking about wrapper inheriting in general...

> cheers,
> Aldo

--Abhijit

Reply via email to