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   345052 use v5.14;
  1         7  
6 1     1   5 use warnings;
  1         1  
  1         32  
7              
8 1     1   5 use Params::ValidationCompiler qw/ validation_for /;
  1         2  
  1         44  
9 1     1   564 use Types::Standard qw/ Enum /;
  1         72269  
  1         8  
10 1     1   834 use Test2::API qw/ context /;
  1         2  
  1         65  
11              
12 1     1   8 use base qw/ Log::Dispatch::Output /;
  1         2  
  1         471  
13              
14 1     1   35287 use namespace::autoclean;
  1         3  
  1         8  
15              
16             our $VERSION = 'v0.2.1';
17              
18              
19             sub new {
20 2     2 0 4984 my $proto = shift;
21 2   33     12 my $class = ref $proto || $proto;
22              
23 2         8 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         3540 my %p = $validator->(@_);
34 2         158 my $self = bless { method => $p{method} }, $class;
35 2         25 $self->_basic_init(%p);
36 2         215 return $self;
37             }
38              
39              
40             sub log_message {
41 2     2 0 650 my $self = shift;
42 2         7 my %p = @_;
43 2         7 my $ctx = context();
44 2         190 my $method = $ctx->can( $self->{method} );
45 2         10 $ctx->$method( $p{message} );
46 2         517 $ctx->release;
47 2         53 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.1
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             If you need this module on Perl v5.10, please use one of the v0.1.x
106             versions of this module. Significant bug or security fixes may be
107             backported to those versions.
108              
109             =head1 SEE ALSO
110              
111             L<Log::Log4perl::Appender::TAP>
112              
113             L<Log::Dispatch::TestDiag>
114              
115             =head1 SOURCE
116              
117             The development version is on github at L<https://github.com/robrwo/Log-Dispatch-TAP>
118             and may be cloned from L<git://github.com/robrwo/Log-Dispatch-TAP.git>
119              
120             =head1 BUGS
121              
122             Please report any bugs or feature requests on the bugtracker website
123             L<https://github.com/robrwo/Log-Dispatch-TAP/issues>
124              
125             When submitting a bug or request, please include a test-file or a
126             patch to an existing test-file that illustrates the bug or desired
127             feature.
128              
129             =head1 AUTHOR
130              
131             Robert Rothenberg <rrwo@cpan.org>
132              
133             Some of the code was adapted from L<Log::Log4perl::Appender::TAP>
134             and L<Log::Dispatch::TestDiag>.
135              
136             =head1 COPYRIGHT AND LICENSE
137              
138             This software is Copyright (c) 2020-2023 by Robert Rothenberg.
139              
140             This is free software, licensed under:
141              
142             The Artistic License 2.0 (GPL Compatible)
143              
144             =cut