package Animal;
sub new { return bless {},"Animal"; }
sub speak { };
1;
package Animal::Dog;
use Animal;
our @ISA = qw/ Animal /;
sub new { return bless {},"Animal::Dog"; }
sub speak { print "Woof!\n"; }
1;
package Animal::Cat;
use Animal;
our @ISA= qw/ Animal /;
sub new { reutrn bless {},"Animal::Cat"; }
sub speak { print "Meow!\n"; }
1;
-- ad nauseum --
####
package Report;
sub new {
shift;
my $type= shift;
my $self = {
format => "html",
destination => undef
};
my $token = (
$type == 1 ? "::HighLevel" : "::Status" );
bless $self,"Report" . $token;
}
sub emit {
my $self = shift;
if { $self->{destination} ) {
if ( $self->{format} eq 'html' ) {
print $self->{destination} $self->as_html();
} else {
print $self->{destination} $self->as_text();
}
} else {
if ( $self -> {format} eq 'html' ) {
print $self->as_html();
} else {
print $self->as_text();
}
}
}
sub set_format {
my ($self,$format} = @_;
$self->{format} = $format;
}
sub set_destination {
my ($self,$destination) =@_;
$self->{destination} = $destination;
}
sub generate {
}
;
package Report::HighLevel;
use Report;
our @ISA=qw/ Report /;
sub generate {
my $self = shift;
# report generation logic here...
}
sub as_html{
# HTML generation code here.
}
sub as_text {
# text generation code here.
}
1;
####
my $report1 = new Report(1); # gets Report::HighLevel
my $report2 = new Report(0); # gets Report::Status
$report1->generate();
$report2->generate();