File Coverage

blib/lib/Log/Dispatch/Handle.pm
Criterion Covered Total %
statement 23 23 100.0
branch 1 2 50.0
condition n/a
subroutine 7 7 100.0
pod 0 2 0.0
total 31 34 91.1


line stmt bran cond sub pod time code
1             package Log::Dispatch::Handle;
2              
3 2     2   1194 use strict;
  2         4  
  2         51  
4 2     2   9 use warnings;
  2         3  
  2         71  
5              
6             our $VERSION = '2.69';
7              
8 2     2   10 use Log::Dispatch::Types;
  2         2  
  2         16  
9 2     2   46577 use Params::ValidationCompiler qw( validation_for );
  2         5  
  2         110  
10              
11 2     2   10 use base qw( Log::Dispatch::Output );
  2         4  
  2         542  
12              
13             {
14             my $validator = validation_for(
15             params => { handle => { type => t('CanPrint') } },
16             slurpy => 1,
17             );
18              
19             sub new {
20 1     1 0 10 my $class = shift;
21 1         16 my %p = $validator->(@_);
22              
23 1         41 my $self = bless { handle => delete $p{handle} }, $class;
24 1         8 $self->_basic_init(%p);
25              
26 1         5 return $self;
27             }
28             }
29              
30             sub log_message {
31 1     1 0 2 my $self = shift;
32 1         4 my %p = @_;
33              
34             $self->{handle}->print( $p{message} )
35 1 50       4 or die "Cannot write to handle: $!";
36             }
37              
38             1;
39              
40             # ABSTRACT: Object for logging to IO::Handle classes
41              
42             __END__
43              
44             =pod
45              
46             =encoding UTF-8
47              
48             =head1 NAME
49              
50             Log::Dispatch::Handle - Object for logging to IO::Handle classes
51              
52             =head1 VERSION
53              
54             version 2.69
55              
56             =head1 SYNOPSIS
57              
58             use Log::Dispatch;
59              
60             my $log = Log::Dispatch->new(
61             outputs => [
62             [
63             'Handle',
64             min_level => 'emerg',
65             handle => $io_socket_object,
66             ],
67             ]
68             );
69              
70             $log->emerg('I am the Lizard King!');
71              
72             =head1 DESCRIPTION
73              
74             This module supplies a very simple object for logging to some sort of
75             handle object. Basically, anything that implements a C<print()>
76             method can be passed the object constructor and it should work.
77              
78             =for Pod::Coverage new log_message
79              
80             =head1 CONSTRUCTOR
81              
82             The constructor takes the following parameters in addition to the standard
83             parameters documented in L<Log::Dispatch::Output>:
84              
85             =over 4
86              
87             =item * handle ($)
88              
89             The handle object. This object must implement a C<print()> method.
90              
91             =back
92              
93             =head1 SUPPORT
94              
95             Bugs may be submitted at L<https://github.com/houseabsolute/Log-Dispatch/issues>.
96              
97             I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>.
98              
99             =head1 SOURCE
100              
101             The source code repository for Log-Dispatch can be found at L<https://github.com/houseabsolute/Log-Dispatch>.
102              
103             =head1 AUTHOR
104              
105             Dave Rolsky <autarch@urth.org>
106              
107             =head1 COPYRIGHT AND LICENSE
108              
109             This software is Copyright (c) 2019 by Dave Rolsky.
110              
111             This is free software, licensed under:
112              
113             The Artistic License 2.0 (GPL Compatible)
114              
115             The full text of the license can be found in the
116             F<LICENSE> file included with this distribution.
117              
118             =cut