You still haven't told us what you are trying to achieve, but it looks like you are setting up a test suite with pluggable tests. I'd structure it somewhat differently by having a test harness class (your Top class) and pluggable classes (your ExtendX classes). You may want a pluggable base class that knows how to hook itself up to the test harness, but most likely you'd do that by creating pluggable class instances and registering them with the harness. Something like this:
#!/usr/bin/perl use strict; use warnings; package Harness; sub new { my ($class, %params) = @_; my $self = bless \%params, $class; return $self; } sub register { my ($self, $plugin) = @_; push @{$self->{plugins}}, $plugin; } sub run { my ($self) = @_; my @results; for my $test (@{$self->{plugins}}) { print "Running ", $test->name(), "\n"; push @results, $test->run($self); } print "$_\n" for @results; } package PluginBase; sub new { my ($class, %params) = @_; my $self = bless \%params, $class; return $self; } sub name { my ($self) = @_; return ref $self; } sub run { my ($self) = @_; return "Skipped " . $self->name() . " test - no run override provi +ded"; } package WinkTest; push @WinkTest::ISA, 'PluginBase'; sub run { my ($self) = @_; my $type = ref $self; return "Wink, wink. Wink test passed OK"; } package BlinkTest; push @BlinkTest::ISA, 'PluginBase'; package main; my $test = Harness->new(); $test->register (WinkTest->new()); $test->register (BlinkTest->new()); $test->run();
Prints:
Running WinkTest Running BlinkTest Wink, wink. Wink test passed OK Skipped BlinkTest test - no run override provided
Please note the PackageName->constructor() style used to invoke package methods. The old constructor PackageName() style is pretty much deprecated because it is prone to parsing difficulties.
In reply to Re^2: Inheritance automation help
by GrandFather
in thread Inheritance automation help
by natelewis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |