diff --git a/src/main/perl/Log.pm b/src/main/perl/Log.pm index a26ef17d..69dd8ec7 100755 --- a/src/main/perl/Log.pm +++ b/src/main/perl/Log.pm @@ -9,17 +9,23 @@ use strict; use warnings; use CAF::Reporter qw($SYSLOG); -use parent qw(CAF::Object); +use parent qw(CAF::Object Exporter); use LC::Exception qw (SUCCESS throw_error); use FileHandle; use Readonly; -Readonly my $FH => 'FH'; +Readonly our $FH => 'FH'; +Readonly our $FILENAME => 'FILENAME'; Readonly my $TSTAMP => 'TSTAMP'; -Readonly my $FILENAME => 'FILENAME'; Readonly my $OPTS => 'OPTS'; +our @EXPORT_OK = qw($FILENAME $FH); + +# $FH is used during DESTROY (and close), but might be +# destroyed itself e.g. during global cleanup +my $_FH = $FH; + my $ec = LC::Exception::Context->new->will_store_all; # TODO: the pod used to say: INHERITANCE: CAF::Reporter @@ -56,14 +62,15 @@ closes the log file, returns SUCCESS on success, undef otherwise =cut +# Called during DESTROY, use $_XYZ flavour sub close ($) { my $self = shift; - return unless (defined $self->{$FH}); + return unless (defined $self->{$_FH}); - $self->{$FH}->close(); - $self->{$FH} = undef; + $self->{$_FH}->close(); + $self->{$_FH} = undef; return SUCCESS; } @@ -191,10 +198,12 @@ Called during garbage collection. Invokes close(). =cut - +# All Readonly here (and in methods called) might be +# cleaned up during global cleanup, so use the $_XYZ +# flavours here (and methods called here). sub DESTROY { my $self = shift; - $self->close() if (defined $self->{$FH}); + $self->close() if (defined $self->{$_FH}); } =pod diff --git a/src/test/perl/log.t b/src/test/perl/log.t index 9d486159..a1c572ac 100644 --- a/src/test/perl/log.t +++ b/src/test/perl/log.t @@ -4,7 +4,7 @@ use warnings; use Test::More; use Test::MockModule; use LC::Exception qw (SUCCESS); -use CAF::Log; +use CAF::Log qw($FH $FILENAME); mkdir('target/test'); @@ -28,6 +28,9 @@ Test all methods for C =cut +is($FILENAME, 'FILENAME', 'Exported FILENAME'); +is($FH, 'FH', 'Exported FH'); + # test failures my $ec = LC::Exception::Context->new()->will_store_errors();