| 1 | package Log::Dispatch::Screen; | ||||||||||
| 2 | |||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 7 | our $VERSION = '2.71'; | |||||||||
| 7 | |||||||||||
| 8 | 7 | ▶ | use Encode qw( encode ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 7 | ▶ | use IO::Handle; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 7 | ▶ | use Log::Dispatch::Types; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 7 | ▶ | use Params::ValidationCompiler qw( validation_for ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 7 | ▶ | use base qw( Log::Dispatch::Output ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | { | ||||||||||
| 16 | 7 | my $validator = validation_for( | |||||||||
| 17 | params => { | ||||||||||
| 18 | stderr => { | ||||||||||
| 19 | type => t('Bool'), | ||||||||||
| 20 | default => 1, | ||||||||||
| 21 | }, | ||||||||||
| 22 | utf8 => { | ||||||||||
| 23 | type => t('Bool'), | ||||||||||
| 24 | default => 0, | ||||||||||
| 25 | }, | ||||||||||
| 26 | }, | ||||||||||
| 27 | slurpy => 1, | ||||||||||
| 28 | ); | ||||||||||
| 29 | |||||||||||
| 30 | 8 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 31 | 8 | my $class = shift; | |||||||||
| 32 | 8 | my %p = $validator->(@_); | |||||||||
| 33 | |||||||||||
| 34 | 8 | my $self = bless { map { $_ => delete $p{$_} } qw( stderr utf8 ) }, | |||||||||
| 35 | $class; | ||||||||||
| 36 | |||||||||||
| 37 | 8 | $self->_basic_init(%p); | |||||||||
| 38 | |||||||||||
| 39 | 8 | return $self; | |||||||||
| 40 | } | ||||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 7 | ▶ | sub log_message { | ||||||||
|
Subroutine
log_message: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 44 | 5 | my $self = shift; | |||||||||
| 45 | 5 | my %p = @_; | |||||||||
| 46 | |||||||||||
| 47 | # This is a bit gross but it's important that we print directly to the | ||||||||||
| 48 | # STDOUT or STDERR handle for backwards compatibility. Various modules | ||||||||||
| 49 | # have tests which rely on this, so we can't open a new filehandle to fd 1 | ||||||||||
| 50 | # or 2 and use that. | ||||||||||
| 51 | my $message | ||||||||||
| 52 | 5 | ▶ | = $self->{utf8} ? encode( 'UTF-8', $p{message} ) : $p{message}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | |||||||||||
| 54 | ## no critic (InputOutput::RequireCheckedSyscalls) | ||||||||||
| 55 | 5 | ▶ | if ( $self->{stderr} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 2 | print STDERR $message; | |||||||||
| 57 | } | ||||||||||
| 58 | else { | ||||||||||
| 59 | 3 | print STDOUT $message; | |||||||||
| 60 | } | ||||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 7 | 1; | |||||||||
| 64 | |||||||||||
| 65 | # ABSTRACT: Object for logging to the screen | ||||||||||
| 66 | |||||||||||
| 67 | __END__ | ||||||||||