Generic.pm

filter: Statementstmt 15.4% 23 / 149 Branchbran 0.0% 0 / 54 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 43.7% 7 / 16 Podpod 0.0% 0 / 10 totaltotal 12.9% 31 / 239 SCAR 67.3
CC
34
Cov
11%
countdown
156.0
print
72.0
_check_args
72.0
CRAP 835.7
« Bus/Socket.pm ↑ Summary Instrument/TRMC2.pm »
1 package Lab::Generic;
2 9 $Lab::Generic::VERSION = '3.881';
3 #ABSTRACT: General function library for the L::M classes
4  
5 9 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶use Lab::Generic::CLOptions;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use Term::ReadKey;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 9 our @OBJECTS = ();
13  
14 sub new {
15 21 ▶ my $proto = shift;
Subroutine new: called CC=2 SCAR=7.1
Pod undocumented
16 21 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
0210
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
17  
18 21 my $self = {};
19 21 push( @OBJECTS, $self );
20  
21 21 bless( $self, $class );
22 21 return $self;
23 }
24  
25 sub set_name {
26 0 ▶ my $self = shift;
Subroutine set_name: not called CC=1 SCAR=6.9
Pod undocumented
27 0 my ($name) = $self->_check_args( \@_, ['name'] );
28 0 $self->{name} = $name;
29 }
30  
31 sub get_name {
32 0 ▶ my $self = shift;
Subroutine get_name: not called CC=1 SCAR=6.9
Pod undocumented
33 0 return $self->{name};
34 }
35  
36 ▶sub abort { }
Subroutine abort: called CC=1 SCAR=0.0
Pod undocumented
37  
38 sub print {
39 0 ▶ my $self = shift;
Subroutine print: not called CC=8 SCAR=42.8
Pod undocumented
40 0 my @data = @_;
41 0 my ( $package, $filename, $line, $subroutine ) = caller(1);
42  
43 0 ▶ if ( ref( @data[0] ) eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref @data[0] eq 'HASH') { } 0 0 0
elsif (ref @data[0] eq 'ARRAY') { } 0 0 0
44 0 ▶ while ( my ( $k, $v ) = each %{ @data[0] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{@data[0];}) 0 0 0
45 0 my $line = "$k => ";
46 0 $line .= $self->print($v);
47 0 ▶ if ( $subroutine =~ /print/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subroutine =~ /print/u) { } 0 0 0
48 0 return $line;
49 }
50 else {
51 0 print $line. "\n";
52 }
53 }
54 }
55 elsif ( ref( @data[0] ) eq 'ARRAY' ) {
56 0 my $line = "[";
57 0 foreach ( @{ @data[0] } ) {
58 0 $line .= $self->print($_);
59 0 $line .= ", ";
60 }
61 0 chop($line);
62 0 chop($line);
63 0 $line .= "]";
64 0 ▶ if ( $subroutine =~ /print/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subroutine =~ /print/u) { } 0 0 0
65 0 return $line;
66 }
67 else {
68 0 print $line. "\n";
69 }
70 }
71 else {
72 0 ▶ if ( $subroutine =~ /print/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subroutine =~ /print/u) { } 0 0 0
73 0 return @data[0];
74 }
75 else {
76 0 print @data[0] . "\n";
77 }
78 }
79  
80 }
81  
82 sub _check_args {
83 0 ▶ my $self = shift;
Subroutine _check_args: not called CC=8 SCAR=42.8
84 0 my $args = shift;
85 0 my $params = shift;
86  
87 0 my $arguments = {};
88  
89 0 my $i = 0;
90 0 foreach my $arg ( @{$args} ) {
91 0 ▶ if ( ref($arg) ne "HASH" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg ne 'HASH') { } 0 0 0
92 0 ▶ if ( defined @{$params}[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined @{$params;}[$i]) 0 0 0
93 0 $arguments->{ @{$params}[$i] } = $arg;
94 }
95 0 $i++;
96 }
97 else {
98 0 %{$arguments} = ( %{$arguments}, %{$arg} );
99 0 $i++;
100 }
101 }
102  
103 0 my @return_args = ();
104  
105 0 foreach my $param ( @{$params} ) {
106 0 ▶ if ( exists $arguments->{$param} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $arguments->{$param}) { } 0 0 0
107 0 push( @return_args, $arguments->{$param} );
108 0 delete $arguments->{$param};
109 }
110 else {
111 0 push( @return_args, undef );
112 }
113 }
114  
115 0 foreach my $param ( 'from_device', 'from_cache'
116 ) # Delete Standard option parameters from $arguments hash if not defined in device driver function
117 {
118 0 ▶ if ( exists $arguments->{$param} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $arguments->{$param}) 0 0 0
119 0 delete $arguments->{$param};
120 }
121 }
122  
123 0 push( @return_args, $arguments );
124  
125 # if (scalar(keys %{$arguments}) > 0)
126 # {
127 # my $errmess = "Unknown parameter given in $self :";
128 # while ( my ($k,$v) = each %{$arguments} )
129 # {
130 # $errmess .= $k." => ".$v."\t";
131 # }
132 # print Lab::Exception::Warning->new( error => $errmess);
133 # }
134  
135 0 return @return_args;
136 }
137  
138 sub my_sleep {
139 0 ▶ my $sleeptime = shift;
Subroutine my_sleep: not called CC=2 SCAR=17.9
Pod undocumented
140 0 my $self = shift;
141 0 my $user_command = shift;
142 0 ▶ if ( $sleeptime >= 5 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sleeptime >= 5) { } 0 0 0
143 0 countdown( $sleeptime * 1e6, $self, $user_command );
144 }
145 else {
146 0 usleep( $sleeptime * 1e6 );
147 }
148 }
149  
150 sub my_usleep {
151 0 ▶ my $sleeptime = shift;
Subroutine my_usleep: not called CC=2 SCAR=17.9
Pod undocumented
152 0 my $self = shift;
153 0 my $user_command = shift;
154 0 ▶ if ( $sleeptime >= 5 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sleeptime >= 5) { } 0 0 0
155 0 countdown( $sleeptime, $self, $user_command );
156 }
157 else {
158 0 usleep($sleeptime);
159 }
160 }
161  
162 sub countdown {
163 0 ▶ my $self = shift;
Subroutine countdown: not called CC=12 SCAR=50.5
Pod undocumented
164 0 my $duration = shift;
165 0 my $user_command = shift;
166  
167 0 ReadMode('cbreak');
168  
169 0 $duration /= 1e6;
170 0 my $hours = int( $duration / 3600 );
171 0 my $minutes = int( ( $duration - $hours * 3600 ) / 60 );
172 0 my $seconds = $duration - $hours * 3600 - $minutes * 60;
173  
174 0 my $t_0 = time();
175  
176 0 local $| = 1;
177  
178 0 my $message = "Waiting for ";
179  
180 0 ▶ if ( $hours > 1 ) { $message .= "$hours hours "; }
Branch: 2 branches
BranchTrueFalseTotal
if ($hours > 1) { } 0 0 0
elsif ($hours == 1) { } 0 0 0
181 0 elsif ( $hours == 1 ) { $message .= "one hour "; }
182 0 ▶ if ( $minutes > 1 ) { $message .= "$minutes minutes "; }
Branch: 2 branches
BranchTrueFalseTotal
if ($minutes > 1) { } 0 0 0
elsif ($minutes == 1) { } 0 0 0
183 0 elsif ( $minutes == 1 ) { $message .= "one minute "; }
184 0 ▶ if ( $seconds > 1 ) { $message .= "$seconds seconds "; }
Branch: 2 branches
BranchTrueFalseTotal
if ($seconds > 1) { } 0 0 0
elsif ($seconds == 1) { } 0 0 0
185 0 elsif ( $seconds == 1 ) { $message .= "one second "; }
186  
187 0 $message .= "\n";
188  
189 0 print $message;
190  
191 0 ▶ while ( ( $t_0 + $duration - time() ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t_0 + $duration - time > 0) 0 0 0
192  
193 0 my $char = ReadKey(1);
194  
195 0 ▶ if ( defined($char) && $char eq 'c' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $char and $char eq 'c') { } 0 0 0
elsif (defined $char) { } 0 0 0
Condition0%0/3
defined $char and $char eq "c"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $char and $char eq "c"
defined $char $char eq "c"
Truth table0%0/3
A and B
A= defined $charB= $char eq "c"
ABresult
0X0
100
111
196 0 last;
197 }
198 elsif ( defined($char) ) {
199 0 ▶ if ( defined $user_command ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $user_command) { } 0 0 0
200 0 $user_command->( $self, $char );
201 }
202 else {
203 0 user_command($char);
204 }
205 }
206  
207 0 my $left = ( $t_0 + $duration - time() );
208 0 my $hours = int( $left / 3600 );
209 0 my $minutes = int( ( $left - $hours * 3600 ) / 60 );
210 0 my $seconds = $left - $hours * 3600 - $minutes * 60;
211  
212 0 print sprintf( "%02d:%02d:%02d", $hours, $minutes, $seconds );
213 0 print "\r";
214  
215 #sleep(1);
216  
217 }
218 0 ReadMode('normal');
219 0 $| = 0;
220 0 print "\n\nGO!\n";
221  
222 }
223  
224 sub timestamp {
225  
226 my (
227 0 ▶ $Sekunden, $Minuten, $Stunden, $Monatstag, $Monat,
Subroutine timestamp: not called CC=6 SCAR=37.4
Pod undocumented
228 $Jahr, $Wochentag, $Jahrestag, $Sommerzeit
229 ) = localtime(time);
230  
231 0 $Monat += 1;
232 0 $Jahrestag += 1;
233 0 ▶ $Monat = $Monat < 10 ? $Monat = "0" . $Monat : $Monat;
Branch: 1 branch
BranchTrueFalseTotal
$Monat < 10 ? : 0 0 0
234 0 ▶ $Monatstag = $Monatstag < 10 ? $Monatstag = "0" . $Monatstag : $Monatstag;
Branch: 1 branch
BranchTrueFalseTotal
$Monatstag < 10 ? : 0 0 0
235 0 ▶ $Stunden = $Stunden < 10 ? $Stunden = "0" . $Stunden : $Stunden;
Branch: 1 branch
BranchTrueFalseTotal
$Stunden < 10 ? : 0 0 0
236 0 ▶ $Minuten = $Minuten < 10 ? $Minuten = "0" . $Minuten : $Minuten;
Branch: 1 branch
BranchTrueFalseTotal
$Minuten < 10 ? : 0 0 0
237 0 ▶ $Sekunden = $Sekunden < 10 ? $Sekunden = "0" . $Sekunden : $Sekunden;
Branch: 1 branch
BranchTrueFalseTotal
$Sekunden < 10 ? : 0 0 0
238 0 $Jahr += 1900;
239  
240 0 return "$Monatstag.$Monat.$Jahr", "$Stunden:$Minuten:$Sekunden";
241  
242 }
243  
244 sub seconds2time {
245 0 ▶ my $duration = shift;
Subroutine seconds2time: not called CC=1 SCAR=6.9
Pod undocumented
246  
247 0 my $hours = int( $duration / 3600 );
248 0 my $minutes = int( ( $duration - $hours * 3600 ) / 60 );
249 0 my $seconds = $duration - $hours * 3600 - $minutes * 60;
250  
251 0 my $formated = $hours . "h " . $minutes . "m " . $seconds . "s ";
252  
253 0 return $formated;
254 }
255  
256 9 ▶use Lab::GenericSignals;
Subroutine BEGIN: called CC=1 SCAR=0.0
257 9 1;
258  
259 __END__
260  
261 =pod
262  
263 =encoding UTF-8
264  
265 =head1 NAME
266  
267 Lab::Generic - General function library for the L::M classes
268  
269 =head1 VERSION
270  
271 version 3.881
272  
273 =head1 COPYRIGHT AND LICENSE
274  
275 This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
276  
277 Copyright 2013 Andreas K. Huettel, Christian Butschkow, Stefan Geissler
278 2014 Alexei Iankilevitch, Andreas K. Huettel, Christian Butschkow
279 2015 Alois Dirnaichner, Christian Butschkow
280 2016 Simon Reinhardt
281 2017 Andreas K. Huettel
282 2019 Simon Reinhardt
283 2020 Andreas K. Huettel
284  
285  
286 This is free software; you can redistribute it and/or modify it under
287 the same terms as the Perl 5 programming language system itself.
288  
289 =cut
« Bus/Socket.pm ↑ Summary Instrument/TRMC2.pm »