Connection/Mock.pm

filter: Statementstmt 92.5% 74 / 80 Branchbran 57.1% 8 / 14 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 15 / 15 Podpod 0.0% 0 / 2 totaltotal 83.4% 101 / 121 SCAR 24.3
CC
11
Cov
85%
compare_hashs
7.0
process_call
4.1
__ANON__
3.1
CRAP 11.4
« Instrument/SR830/AuxOut.pm ↑ Summary Moose/Instrument/Keithley2450.pm »
1 package Lab::Connection::Mock;
2 #ABSTRACT: ???
3 6 $Lab::Connection::Mock::VERSION = '3.881';
4 6 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 ▶use Class::Method::Modifiers;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use YAML::XS qw/Dump LoadFile/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 6 ▶use Lab::Connection::LogMethodCall qw/dump_method_call/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶use parent 'Lab::Connection';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18  
19 6 our %fields = (
20 logfile => undef,
21 log_index => 0,
22 log_list => undef,
23 );
24  
25 around 'new' => sub {
26 5 ▶ my $orig = shift;
Subroutine __ANON__: called CC=3 SCAR=11.4
27 5 my $proto = shift;
28 5 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
050
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
29 5 my $twin = undef;
30  
31 # getting fields and _permitted from parent class
32 5 my $self = $class->$orig(@_);
33  
34 5 $self->_construct($class);
35  
36 # Open the log file.
37 5 my $logfile = $self->logfile();
38 5 ▶ if ( not defined $logfile ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $logfile) 0 5 5
39 0 croak 'missing "logfile" parameter in connection';
40 }
41  
42 5 my @logs = LoadFile($logfile);
43 5 $self->log_list( [@logs] );
44  
45 5 return $self;
46 6 };
47  
48 # If all values are scalars, we don't need stuff like Data::Compare.
49 sub compare_hashs {
50 664 ▶ my $a = shift;
Subroutine compare_hashs: called CC=6 SCAR=19.5
Pod undocumented
51 664 my $b = shift;
52  
53 664 my @keys_a = keys %{$a};
54 664 my @keys_b = keys %{$b};
55  
56 664 my $len_a = @keys_a;
57 664 my $len_b = @keys_b;
58  
59 # compare size
60 664 ▶ if ( $len_a != $len_b ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len_a != $len_b) 0 664 664
61 0 return 1;
62 }
63 664 for my $key (@keys_a) {
64 1676 ▶ if ( ref $a->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $a->{$key}) 0 1676 1676
65 0 die "expected scalar";
66 }
67 1676 ▶ if ( not exists $b->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $b->{$key}) 0 1676 1676
68 0 return 1;
69 }
70 1676 ▶ if ( $a->{$key} ne $b->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a->{$key} ne $b->{$key}) 0 1676 1676
71 0 return 1;
72 }
73 }
74 664 return 0;
75 }
76  
77 sub process_call {
78 672 ▶ my $method = shift;
Subroutine process_call: called CC=4 SCAR=14.0
Pod undocumented
79 672 my $self = shift;
80  
81 672 my $index = $self->log_index();
82  
83 # Hack: $self->timeout is called early in Lab::Connection::configure.
84 672 ▶ if ( not defined $self->log_list() and $method eq 'timeout' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->log_list and $method eq "timeout") 8 664 672
Condition66%2/3
not defined $self->log_list and $method eq "timeout"
!ll&&!rl&&r
66408
MC/DC50%1/2
not defined $self->log_list and $method eq "timeout"
not defined $self->log_list $method eq "timeout"
Truth table66%2/3
not(A) and B
A= not defined $self->log_listB= $method eq "timeout"
ABresult
0X0
100
111
85 8 return $self->{config}->{timeout};
86 }
87  
88 664 my $received = dump_method_call( $index, $method, @_ );
89  
90 664 my $expected = $self->log_list()->[$index];
91  
92 664 my $retval = delete $expected->{retval};
93  
94 664 ▶ if ( compare_hashs( $received, $expected ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (compare_hashs($received, $expected)) 0 664 664
95 0 croak "Mock connection:\nreceived:\n", Dump($received),
96 "\nexpected:\n", Dump($expected);
97 }
98  
99 664 $self->log_index( ++$index );
100 664 return $retval;
101 }
102  
103 6 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 672 ▶ my $orig = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
109 672 return process_call( $method, @_ );
110 66 };
111 }
112  
113 sub _setbus {
114  
115 # No bus for this connection, so do nothing.
116 5 ▶ return;
Subroutine _setbus: called CC=1 SCAR=0.0
117 }
118 6 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.881
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
« Instrument/SR830/AuxOut.pm ↑ Summary Moose/Instrument/Keithley2450.pm »