File Coverage

blib/lib/JMAP/Tester/Logger.pm
Criterion Covered Total %
statement 12 14 85.7
branch n/a
condition n/a
subroutine 4 5 80.0
pod 0 1 0.0
total 16 20 80.0


line stmt bran cond sub pod time code
1             package JMAP::Tester::Logger 0.101;
2              
3 1     1   622 use Moo::Role;
  1         3  
  1         8  
4              
5 1     1   882 use JMAP::Tester::LogWriter;
  1         5  
  1         80  
6 1     1   12 use Params::Util qw(_CODELIKE _HANDLE _SCALAR0);
  1         3  
  1         114  
7              
8 1     1   8 use namespace::clean;
  1         2  
  1         9  
9              
10             has writer => (
11             is => 'ro',
12             isa => sub {
13             die "no writer provided" unless $_[0];
14             die "writer provided can't be called as code" unless $_[0]->does('JMAP::Tester::LogWriter');
15             },
16             coerce => sub {
17             my $value = $_[0];
18             return JMAP::Tester::LogWriter::Code->new({ code => $value })
19             if _CODELIKE($value);
20              
21             return JMAP::Tester::LogWriter::Handle->new({ handle => $value })
22             if _HANDLE($value);
23              
24             return JMAP::Tester::LogWriter::Code->new({ code => sub{} })
25             if _SCALAR0($value) && ! defined $$value;
26              
27             if (defined $value && ! ref $value && length $value) {
28             if ($value =~ /\A-([1-9][0-9]*)\z/) {
29             open my $handle, '>&', "$1"
30             or die "can't dup fd $1 for logger output: $!";
31             $handle->autoflush(1);
32             return JMAP::Tester::LogWriter::Handle->new({ handle => $handle });
33             }
34              
35             return JMAP::Tester::LogWriter::Filename->new({
36             filename_template => $value
37             });
38             }
39              
40             return $value;
41             },
42             required => 1,
43             );
44              
45             sub write {
46 0     0 0   my ($self, $string) = @_;
47 0           $self->writer->write( $string );
48             }
49              
50             requires 'log_jmap_request';
51             requires 'log_jmap_response';
52              
53             requires 'log_upload_request';
54             requires 'log_upload_response';
55              
56             requires 'log_download_request';
57             requires 'log_download_response';
58              
59             1;
60              
61             __END__