File Coverage

blib/lib/Lab/Connection/LogMethodCall.pm
Criterion Covered Total %
statement 31 34 91.1
branch 8 10 80.0
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 45 51 88.2


line stmt bran cond sub pod time code
1             package Lab::Connection::LogMethodCall;
2             #ABSTRACT: ???
3             $Lab::Connection::LogMethodCall::VERSION = '3.881';
4 6     6   3269 use v5.20;
  6         31  
5              
6 6     6   38 use warnings;
  6         18  
  6         161  
7 6     6   34 use strict;
  6         12  
  6         144  
8              
9 6     6   33 use Carp;
  6         23  
  6         359  
10 6     6   44 use Exporter qw(import);
  6         25  
  6         2016  
11              
12             our @EXPORT = qw(dump_method_call);
13              
14             # Return a hashref, which describes the method call. Does not include the
15             # methods's return value.
16             sub dump_method_call {
17 664     664 0 1055 my $id = shift;
18 664         975 my $method = shift;
19 664         1274 my @args = @_;
20              
21 664         1676 my $log = {
22             id => $id,
23             method => $method,
24             };
25              
26 664 100       2804 if ( $method =~ /Clear|block_connection|unblock_connection|is_blocked/ ) {
27              
28             # These method take no arguments.
29 316         822 return $log;
30             }
31              
32 348 50       777 if ( $method eq 'timeout' ) {
33              
34             # timeout takes a single argument.
35 0         0 $log->{timeout} = $args[0];
36 0         0 return $log;
37             }
38              
39             # The remaining methods get either a flat hash or a hashref.
40              
41 348         493 my $config;
42              
43 348 100       715 if ( ref $args[0] eq 'HASH' ) {
44 253         401 $config = $args[0];
45             }
46             else {
47 95         204 $config = {@args};
48             }
49              
50 348         699 for my $param (qw/command read_length brutal wait_query/) {
51 1392 100       2754 if ( defined $config->{$param} ) {
52 348         583 my $key = $config->{$param};
53 348 50       662 if ( ref $key ) {
54              
55             # Should never happen.
56 0         0 croak "$param is a ref";
57             }
58 348         736 $log->{$param} = $key;
59             }
60             }
61              
62 348         919 return $log;
63             }
64              
65             1;
66              
67             __END__
68              
69             =pod
70              
71             =encoding UTF-8
72              
73             =head1 NAME
74              
75             Lab::Connection::LogMethodCall - ???
76              
77             =head1 VERSION
78              
79             version 3.881
80              
81             =head1 COPYRIGHT AND LICENSE
82              
83             This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
84              
85             Copyright 2016 Simon Reinhardt
86             2017 Andreas K. Huettel
87             2020 Andreas K. Huettel
88              
89              
90             This is free software; you can redistribute it and/or modify it under
91             the same terms as the Perl 5 programming language system itself.
92              
93             =cut