Logger to obj #10

Open
wants to merge 1 commit into from
View
23 lib/Test/Mini/Runner.pm
@@ -80,6 +80,19 @@ sub filter {
# @return Logger instance.
sub logger {
my $self = shift;
+
+ unless (ref($self->{logger})) { #logger is still a string, make an obj
+ my $logger = $self->{logger};
+ try {
+ eval "require $logger;" or die $@;
+ }
+ catch {
+ $logger = qq{Test::Mini::Logger::$logger};
+ eval "require $logger;" or die $@;
+ };
+ $self->{logger} = $logger->new(verbose => $self->verbose);
+ }
+
return $self->{logger};
}
@@ -104,16 +117,6 @@ sub exit_code {
# @return The result of the {#run_test_suite} call.
sub run {
my ($self) = @_;
- my $logger = $self->logger;
- try {
- eval "require $logger;" or die $@;
- }
- catch {
- eval "require Test::Mini::Logger::$logger;" or die $@;
- };
-
- $logger = $logger->new(verbose => $self->verbose);
- $self->{logger} = $logger;
return $self->run_test_suite(filter => $self->filter, seed => $self->seed);
}
View
22 t/logger_auto_object.t
@@ -0,0 +1,22 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Test::More qw{no_plan};
+
+BEGIN {
+
+ use_ok('Test::Mini::Runner');
+ can_ok('Test::Mini::Runner', qw{
+ logger
+ });
+
+};
+#-----------------------------------------------------------------
+ok my $r = Test::Mini::Runner->new;
+isa_ok $r, 'Test::Mini::Runner';
+
+is $r->{logger}, 'Test::Mini::Logger::TAP';
+isa_ok $r->logger, 'Test::Mini::Logger::TAP';
+ok $r->{logger} = 'TAP';
+isa_ok $r->logger, 'Test::Mini::Logger::TAP';
+