| 1 | package Lab::Connection::Log; | ||||||||||||||||||||
| 2 | #ABSTRACT: Role adding logging capability to connections | ||||||||||||||||||||
| 3 | 1 | $Lab::Connection::Log::VERSION = '3.881'; | |||||||||||||||||||
| 4 | 1 | ▶ | use v5.20; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | ▶ | use Role::Tiny; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 1 | ▶ | use YAML::XS; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 1 | ▶ | use autodie; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 1 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 1 | ▶ | use Lab::Connection::LogMethodCall qw(dump_method_call); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | around 'new' => sub { | ||||||||||||||||||||
| 19 | 0 | ▶ | my $orig = shift; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 20 | 0 | my $proto = shift; | |||||||||||||||||||
| 21 | 0 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 22 | 0 | my $twin = undef; | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | # getting fields and _permitted from parent class | ||||||||||||||||||||
| 25 | 0 | my $self = $class->$orig(@_); | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 0 | $self->_construct($class); | |||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | # open the log file | ||||||||||||||||||||
| 30 | 0 | my $logfile = $self->logfile(); | |||||||||||||||||||
| 31 | 0 | ▶ | if ( not defined $logfile ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | 0 | croak 'missing "logfile" parameter in connection'; | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | # FIXME: Currently it's not possible to have a filehandle in %fields, as | ||||||||||||||||||||
| 36 | # this breaks the dclone used in Sweep.pm. | ||||||||||||||||||||
| 37 | 0 | open my $fh, '>', $self->logfile(); | |||||||||||||||||||
| 38 | 0 | close $fh; | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 0 | return $self; | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 1 | }; | |||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | sub dump_ref { | ||||||||||||||||||||
| 45 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
dump_ref: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 46 | 0 | my $ref = shift; | |||||||||||||||||||
| 47 | 0 | open my $fh, '>>', $self->logfile(); | |||||||||||||||||||
| 48 | 0 | print {$fh} Dump($ref); | |||||||||||||||||||
| 49 | 0 | close $fh; | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 1 | for my $method ( | |||||||||||||||||||
| 53 | qw/Clear Write Read Query BrutalRead LongQuery BrutalQuery | ||||||||||||||||||||
| 54 | timeout block_connection unblock_connection is_blocked/ | ||||||||||||||||||||
| 55 | ) { | ||||||||||||||||||||
| 56 | around $method => sub { | ||||||||||||||||||||
| 57 | 0 | ▶ | my $orig = shift; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 58 | 0 | my $self = shift; | |||||||||||||||||||
| 59 | 0 | my $retval = $self->$orig(@_); | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | # Inside the around modifier, we need to skip 2 levels to get to the | ||||||||||||||||||||
| 62 | # true caller. | ||||||||||||||||||||
| 63 | 0 | my $caller = caller(2); | |||||||||||||||||||
| 64 | 0 | ▶ | if ( $caller !~ /Lab::Connection.*/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 0 | my $index = $self->log_index(); | |||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 0 | my $log = dump_method_call( $index, $method, @_ ); | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 0 | $log->{retval} = $retval; | |||||||||||||||||||
| 71 | 0 | $self->dump_ref($log); | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 0 | $self->log_index( ++$index ); | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | 0 | return $retval; | |||||||||||||||||||
| 76 | 11 | }; | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 1 | 1; | |||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | __END__ | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | =pod | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | =encoding UTF-8 | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | =head1 NAME | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | Lab::Connection::Log - Role adding logging capability to connections | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | =head1 VERSION | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | version 3.881 | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | This software is copyright (c) 2023 by the Lab::Measurement team; in detail: | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | Copyright 2016 Simon Reinhardt | ||||||||||||||||||||
| 100 | 2017 Andreas K. Huettel | ||||||||||||||||||||
| 101 | 2020 Andreas K. Huettel | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 105 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | =cut | ||||||||||||||||||||