in reply to Re: Inheritance automation help
in thread Inheritance automation help
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Inheritance automation help
by natelewis (Novice) on Apr 17, 2012 at 19:14 UTC | |
by chromatic (Archbishop) on Apr 17, 2012 at 20:40 UTC | |
|
Re^3: Inheritance automation help
by natelewis (Novice) on Apr 11, 2012 at 22:41 UTC |