File Coverage

blib/lib/Log/Dispatch/TAP.pm
Criterion Covered Total %
statement 34 34 100.0
branch n/a
condition 1 3 33.3
subroutine 9 9 100.0
pod 0 2 0.0
total 44 48 91.6


line stmt bran cond sub pod time code
1             package Log::Dispatch::TAP;
2              
3             # ABSTRACT: Log to TAP output
4              
5 1     1   366632 use v5.14;
  1         3  
6 1     1   4 use warnings;
  1         2  
  1         43  
7              
8 1     1   3 use Params::ValidationCompiler qw/ validation_for /;
  1         2  
  1         38  
9 1     1   510 use Types::Standard qw/ Enum /;
  1         130115  
  1         19  
10 1     1   3567 use Test2::API qw/ context /;
  1         2  
  1         92  
11              
12 1     1   9 use parent qw/ Log::Dispatch::Output /;
  1         2  
  1         11  
13              
14 1     1   41174 use namespace::autoclean;
  1         3  
  1         11  
15              
16             our $VERSION = 'v0.2.2';
17              
18              
19             sub new {
20 2     2 0 292972 my $proto = shift;
21 2   33     17 my $class = ref $proto || $proto;
22              
23 2         13 state $validator = validation_for(
24             params => {
25             method => {
26             type => Enum[qw/ note diag /],
27             default => 'note',
28             },
29             },
30             slurpy => 1,
31             );
32              
33 2         33576 my %p = $validator->(@_);
34 2         166 my $self = bless { method => $p{method} }, $class;
35 2         24 $self->_basic_init(%p);
36 2         272 return $self;
37             }
38              
39              
40             sub log_message {
41 2     2 0 887 my $self = shift;
42 2         8 my %p = @_;
43 2         11 my $ctx = context();
44 2         276 my $method = $ctx->can( $self->{method} );
45 2         13 $ctx->$method( $p{message} );
46 2         723 $ctx->release;
47 2         90 return;
48             }
49              
50              
51             1;
52              
53             __END__
54              
55             =pod
56              
57             =encoding UTF-8
58              
59             =head1 NAME
60              
61             Log::Dispatch::TAP - Log to TAP output
62              
63             =head1 VERSION
64              
65             version v0.2.2
66              
67             =head1 SYNOPSIS
68              
69             use Log::Dispatch;
70              
71             my $logger = Log::Dispatch->new(
72             outputs => [
73             [
74             'TAP',
75             method => 'note',
76             min_level => 'debug',
77             ]
78             );
79              
80             =head1 DESCRIPTION
81              
82             This module provides a L<Log::Dispatch> output sink for logging to
83             L<Test::Simple> diagnostics.
84              
85             It is similar to L<Log::Dispatch::TestDiag>.
86              
87             =head1 CONSTRUCTOR
88              
89             The constructor takes the following parameter in addition to the
90             standard parameters for L<Log::Dispatch::Output>.
91              
92             =head2 method
93              
94             This is the logging method, which is either C<note> or C<diag>
95             (corresponding to those functions in L<Test::More>).
96              
97             =for Pod::Coverage log_message
98              
99             =head1 SUPPORT FOR OLDER PERL VERSIONS
100              
101             Since v0.2.0, the this module requires Perl v5.14 or later.
102              
103             Future releases may only support Perl versions released in the last ten years.
104              
105             =head1 SEE ALSO
106              
107             L<Log::Log4perl::Appender::TAP>
108              
109             L<Log::Dispatch::TestDiag>
110              
111             =head1 SOURCE
112              
113             The development version is on github at L<https://github.com/robrwo/Log-Dispatch-TAP>
114             and may be cloned from L<git://github.com/robrwo/Log-Dispatch-TAP.git>
115              
116             =head1 BUGS
117              
118             Please report any bugs or feature requests on the bugtracker website
119             L<https://github.com/robrwo/Log-Dispatch-TAP/issues>
120              
121             When submitting a bug or request, please include a test-file or a
122             patch to an existing test-file that illustrates the bug or desired
123             feature.
124              
125             =head2 Reporting Security Vulnerabilities
126              
127             Security issues should not be reported on the bugtracker website. Please see F<SECURITY.md> for instructions how to
128             report security vulnerabilities
129              
130             =head1 AUTHOR
131              
132             Robert Rothenberg <rrwo@cpan.org>
133              
134             Some of the code was adapted from L<Log::Log4perl::Appender::TAP>
135             and L<Log::Dispatch::TestDiag>.
136              
137             =head1 COPYRIGHT AND LICENSE
138              
139             This software is Copyright (c) 2020-2025 by Robert Rothenberg.
140              
141             This is free software, licensed under:
142              
143             The Artistic License 2.0 (GPL Compatible)
144              
145             =cut