Dupout.pm

filter: Statementstmt 89.3% 42 / 47 Branchbran 25.0% 2 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 10 / 12 Podpod 0.0% 0 / 1 totaltotal 79.4% 54 / 68 CC 5 SCAR 9.0
CC
5
Cov
80%
init
5.2
__ANON__
4.3
__ANON__
1.1
CRAP 2.5
↑ Summary Duperr.pm »
1 package Log::Any::Adapter::Dupout;
2  
3 #
4 # Cunning adapter for logging to a duplicate of STDOUT
5 #
6  
7 2 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use utf8::all;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Log::Any::Adapter::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use base qw/Log::Any::Adapter::Base/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 our $VERSION = '0.05';
18  
19 1 ▶sub init {
Subroutine init: called CC=4 SCAR=16.4
Pod undocumented
20 1 my ($self) = @_;
21  
22 # Duplicate STDOUT
23 1 ▶ open( $self->{fh}, '>&', STDOUT ) or croak "Can't dup STDOUT: $!"; ## no critic [InputOutput::RequireBriefOpen]
Branch: 1 branch
BranchTrueFalseTotal
open $self->{"fh"}, ">&", "STDOUT" or croak("Can't dup STDOUT: $!") 1 0 1
24  
25 1 ▶ if ( exists $self->{log_level} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'log_level'}) { } 0 1 1
26 $self->{log_level} = Log::Any::Adapter::Util::numeric_level( $self->{log_level} )
27 0 ▶ unless $self->{log_level} =~ /^\d+$/x;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"log_level"} =~ /^\d+$/ux 0 0 0
28 }
29 else {
30 1 $self->{log_level} = Log::Any::Adapter::Util::numeric_level('trace');
31 }
32  
33 1 return;
34 }
35  
36 2 foreach my $method ( Log::Any::Adapter::Util::logging_methods() ) {
37 2 ▶ no strict 'refs'; ## no critic (ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 18 my $method_level = Log::Any::Adapter::Util::numeric_level($method);
40  
41 18 ▶ *{$method} = sub {
Subroutine __ANON__: not called CC=2 SCAR=14.6
42 0 my ( $self, $text ) = @_;
43  
44 0 ▶ return if $method_level > $self->{log_level};
Branch: 1 branch
BranchTrueFalseTotal
if $method_level > $self->{"log_level"} 0 0 0
45  
46 0 $self->{fh}->print("$text\n");
47 18 };
48 }
49  
50 2 foreach my $method ( Log::Any::Adapter::Util::detection_methods() ) {
51 2 ▶ no strict 'refs'; ## no critic (ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 18 my $base = substr( $method, 3 );
54  
55 18 my $method_level = Log::Any::Adapter::Util::numeric_level($base);
56  
57 18 ▶ *{$method} = sub {
Subroutine __ANON__: not called CC=1 SCAR=1.2
58 0 return !!( $method_level <= $_[0]->{log_level} );
59 18 };
60 }
61  
62 2 1;
63  
64 __END__
↑ Summary Duperr.pm »