| 1 | package Lab::Connection::LogMethodCall; | ||
| 2 | #ABSTRACT: ??? | ||
| 3 | $Lab::Connection::LogMethodCall::VERSION = '3.899'; | ||
| 4 | use v5.20; | ||
| 5 | |||
| 6 | use warnings; | ||
| 7 | use strict; | ||
| 8 | |||
| 9 | use Carp; | ||
| 10 | use Exporter qw(import); | ||
| 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 | my $id = shift; | ||
| 18 | my $method = shift; | ||
| 19 | my @args = @_; | ||
| 20 | |||
| 21 | my $log = { | ||
| 22 | id => $id, | ||
| 23 | method => $method, | ||
| 24 | }; | ||
| 25 | |||
| 26 | if ( $method =~ /Clear|block_connection|unblock_connection|is_blocked/ ) { | ||
| 27 | |||
| 28 | # These method take no arguments. | ||
| 29 | return $log; | ||
| 30 | } | ||
| 31 | |||
| 32 | if ( $method eq 'timeout' ) { | ||
| 33 | |||
| 34 | # timeout takes a single argument. | ||
| 35 | $log->{timeout} = $args[0]; | ||
| 36 | return $log; | ||
| 37 | } | ||
| 38 | |||
| 39 | # The remaining methods get either a flat hash or a hashref. | ||
| 40 | |||
| 41 | my $config; | ||
| 42 | |||
| 43 | if ( ref $args[0] eq 'HASH' ) { | ||
| 44 | $config = $args[0]; | ||
| 45 | } | ||
| 46 | else { | ||
| 47 | $config = {@args}; | ||
| 48 | } | ||
| 49 | |||
| 50 | for my $param (qw/command read_length brutal wait_query/) { | ||
| 51 | if ( defined $config->{$param} ) { | ||
| 52 | my $key = $config->{$param}; | ||
| 53 | if ( ref $key ) { | ||
| 54 | |||
| 55 | # Should never happen. | ||
| 56 | croak "$param is a ref"; | ||
| 57 | } | ||
| 58 | $log->{$param} = $key; | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | return $log; | ||
| 63 | } | ||
| 64 | |||
| 65 | 1; | ||
| 66 | |||
| 67 | __END__ |