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;