line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lab::Connection::Mock; |
2
|
|
|
|
|
|
|
#ABSTRACT: ??? |
3
|
|
|
|
|
|
|
$Lab::Connection::Mock::VERSION = '3.880'; |
4
|
6
|
|
|
6
|
|
3268
|
use v5.20; |
|
6
|
|
|
|
|
32
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
36
|
use warnings; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
202
|
|
7
|
6
|
|
|
6
|
|
35
|
use strict; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
141
|
|
8
|
|
|
|
|
|
|
|
9
|
6
|
|
|
6
|
|
3406
|
use Class::Method::Modifiers; |
|
6
|
|
|
|
|
10313
|
|
|
6
|
|
|
|
|
393
|
|
10
|
6
|
|
|
6
|
|
2165
|
use YAML::XS qw/Dump LoadFile/; |
|
6
|
|
|
|
|
14581
|
|
|
6
|
|
|
|
|
403
|
|
11
|
6
|
|
|
6
|
|
55
|
use Data::Dumper; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
264
|
|
12
|
6
|
|
|
6
|
|
2547
|
use autodie; |
|
6
|
|
|
|
|
70159
|
|
|
6
|
|
|
|
|
40
|
|
13
|
6
|
|
|
6
|
|
41330
|
use Carp; |
|
6
|
|
|
|
|
25
|
|
|
6
|
|
|
|
|
424
|
|
14
|
|
|
|
|
|
|
|
15
|
6
|
|
|
6
|
|
2914
|
use Lab::Connection::LogMethodCall qw/dump_method_call/; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
340
|
|
16
|
6
|
|
|
6
|
|
57
|
use parent 'Lab::Connection'; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
41
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our %fields = ( |
20
|
|
|
|
|
|
|
logfile => undef, |
21
|
|
|
|
|
|
|
log_index => 0, |
22
|
|
|
|
|
|
|
log_list => undef, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
around 'new' => sub { |
26
|
|
|
|
|
|
|
my $orig = shift; |
27
|
|
|
|
|
|
|
my $proto = shift; |
28
|
|
|
|
|
|
|
my $class = ref($proto) || $proto; |
29
|
|
|
|
|
|
|
my $twin = undef; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# getting fields and _permitted from parent class |
32
|
|
|
|
|
|
|
my $self = $class->$orig(@_); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$self->_construct($class); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Open the log file. |
37
|
|
|
|
|
|
|
my $logfile = $self->logfile(); |
38
|
|
|
|
|
|
|
if ( not defined $logfile ) { |
39
|
|
|
|
|
|
|
croak 'missing "logfile" parameter in connection'; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my @logs = LoadFile($logfile); |
43
|
|
|
|
|
|
|
$self->log_list( [@logs] ); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
return $self; |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# If all values are scalars, we don't need stuff like Data::Compare. |
49
|
|
|
|
|
|
|
sub compare_hashs { |
50
|
664
|
|
|
664
|
0
|
940
|
my $a = shift; |
51
|
664
|
|
|
|
|
901
|
my $b = shift; |
52
|
|
|
|
|
|
|
|
53
|
664
|
|
|
|
|
867
|
my @keys_a = keys %{$a}; |
|
664
|
|
|
|
|
1875
|
|
54
|
664
|
|
|
|
|
1066
|
my @keys_b = keys %{$b}; |
|
664
|
|
|
|
|
1423
|
|
55
|
|
|
|
|
|
|
|
56
|
664
|
|
|
|
|
1028
|
my $len_a = @keys_a; |
57
|
664
|
|
|
|
|
974
|
my $len_b = @keys_b; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# compare size |
60
|
664
|
50
|
|
|
|
1396
|
if ( $len_a != $len_b ) { |
61
|
0
|
|
|
|
|
0
|
return 1; |
62
|
|
|
|
|
|
|
} |
63
|
664
|
|
|
|
|
1174
|
for my $key (@keys_a) { |
64
|
1676
|
50
|
|
|
|
2917
|
if ( ref $a->{$key} ) { |
65
|
0
|
|
|
|
|
0
|
die "expected scalar"; |
66
|
|
|
|
|
|
|
} |
67
|
1676
|
50
|
|
|
|
2819
|
if ( not exists $b->{$key} ) { |
68
|
0
|
|
|
|
|
0
|
return 1; |
69
|
|
|
|
|
|
|
} |
70
|
1676
|
50
|
|
|
|
3782
|
if ( $a->{$key} ne $b->{$key} ) { |
71
|
0
|
|
|
|
|
0
|
return 1; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
664
|
|
|
|
|
1651
|
return 0; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub process_call { |
78
|
672
|
|
|
672
|
0
|
1051
|
my $method = shift; |
79
|
672
|
|
|
|
|
900
|
my $self = shift; |
80
|
|
|
|
|
|
|
|
81
|
672
|
|
|
|
|
3027
|
my $index = $self->log_index(); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Hack: $self->timeout is called early in Lab::Connection::configure. |
84
|
672
|
100
|
66
|
|
|
2406
|
if ( not defined $self->log_list() and $method eq 'timeout' ) { |
85
|
8
|
|
|
|
|
33
|
return $self->{config}->{timeout}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
664
|
|
|
|
|
1755
|
my $received = dump_method_call( $index, $method, @_ ); |
89
|
|
|
|
|
|
|
|
90
|
664
|
|
|
|
|
2521
|
my $expected = $self->log_list()->[$index]; |
91
|
|
|
|
|
|
|
|
92
|
664
|
|
|
|
|
1596
|
my $retval = delete $expected->{retval}; |
93
|
|
|
|
|
|
|
|
94
|
664
|
50
|
|
|
|
1223
|
if ( compare_hashs( $received, $expected ) ) { |
95
|
0
|
|
|
|
|
0
|
croak "Mock connection:\nreceived:\n", Dump($received), |
96
|
|
|
|
|
|
|
"\nexpected:\n", Dump($expected); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
664
|
|
|
|
|
2954
|
$self->log_index( ++$index ); |
100
|
664
|
|
|
|
|
2802
|
return $retval; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
for my $method ( |
104
|
|
|
|
|
|
|
qw/Clear Write Read Query BrutalRead LongQuery BrutalQuery timeout |
105
|
|
|
|
|
|
|
block_connection unblock_connection is_blocked/ |
106
|
|
|
|
|
|
|
) { |
107
|
|
|
|
|
|
|
around $method => sub { |
108
|
|
|
|
|
|
|
my $orig = shift; |
109
|
|
|
|
|
|
|
return process_call( $method, @_ ); |
110
|
|
|
|
|
|
|
}; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _setbus { |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# No bus for this connection, so do nothing. |
116
|
5
|
|
|
5
|
|
14
|
return; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=pod |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=encoding UTF-8 |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 NAME |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Lab::Connection::Mock - ??? |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 VERSION |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
version 3.880 |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
This software is copyright (c) 2023 by the Lab::Measurement team; in detail: |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Copyright 2016 Simon Reinhardt |
139
|
|
|
|
|
|
|
2017 Andreas K. Huettel |
140
|
|
|
|
|
|
|
2020 Andreas K. Huettel |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
144
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |