package Test_logger; sub new { my $pkg = shift; my $self = { logfile => "/tmp/test_logger.log", # default @_ # merge in user-specified attributes }; open my $fh, ">", $self->{logfile} or die "Cannot open logfile '$self->{logfile}': $!"; $self->{logfh} = $fh; return bless $self, $pkg; } sub message { my $self = shift; my $msg = shift; my $fh = $self->{logfh}; print $fh "$msg\n"; } 1;