| 1 | #PODNAME: Lab::XPRESS::Utilities | ||||||||||||||||||||||||||||||||
| 2 | #ABSTRACT: Global utility functions for XPRESS | ||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use v5.20; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 8 | ▶ | no strict; # FIXME | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | #note: this is no "package" | ||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 8 | ▶ | use Term::ReadKey; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use Time::HiRes qw/usleep/, qw/time/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | # collection of some useful subroutines: | ||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | sub my_sleep { | ||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | my $sleeptime = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
my_sleep: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 17 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 18 | 0 | my $user_command = shift; | |||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | if ( $sleeptime >= 5 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 20 | 0 | countdown( $sleeptime * 1e6, $self, $user_command ); | |||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||
| 22 | else { | ||||||||||||||||||||||||||||||||
| 23 | 0 | usleep( $sleeptime * 1e6 ); | |||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | sub my_usleep { | ||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | my $sleeptime = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
my_usleep: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 29 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 30 | 0 | my $user_command = shift; | |||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | if ( $sleep_time >= 5 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 32 | 0 | countdown( $sleeptime, $self, $user_command ); | |||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||
| 34 | else { | ||||||||||||||||||||||||||||||||
| 35 | 0 | usleep($sleeptime); | |||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | sub countdown { | ||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | my $duration = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
countdown: not called CC=12 SCAR=50.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 41 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 42 | 0 | my $user_command = shift; | |||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 0 | ReadMode('cbreak'); | |||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 0 | $duration /= 1e6; | |||||||||||||||||||||||||||||||
| 47 | 0 | my $hours = int( $duration / 3600 ); | |||||||||||||||||||||||||||||||
| 48 | 0 | my $minutes = int( ( $duration - $hours * 3600 ) / 60 ); | |||||||||||||||||||||||||||||||
| 49 | 0 | my $seconds = $duration - $hours * 3600 - $minutes * 60; | |||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 0 | my $t_0 = time(); | |||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 0 | local $| = 1; | |||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 0 | my $message = "Waiting for "; | |||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ( $hours > 1 ) { $message .= "$hours hours "; } | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 58 | 0 | elsif ( $hours == 1 ) { $message .= "one hour "; } | |||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if ( $minutes > 1 ) { $message .= "$minutes minutes "; } | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 60 | 0 | elsif ( $minutes == 1 ) { $message .= "one minute "; } | |||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ( $seconds > 1 ) { $message .= "$seconds seconds "; } | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 62 | 0 | elsif ( $seconds == 1 ) { $message .= "one second "; } | |||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 0 | $message .= "\n"; | |||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | 0 | print $message; | |||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | while ( ( $t_0 + $duration - time() ) > 0 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | 0 | my $char = ReadKey(1); | |||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if ( defined($char) && $char eq 'c' ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
defined $char and $char eq "c"
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"
| |||||||||||||||||||||||||||||||||
| 73 | 0 | last; | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | elsif ( defined($char) ) { | ||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ( defined $user_command ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 77 | 0 | $user_command->( $self, $char ); | |||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | else { | ||||||||||||||||||||||||||||||||
| 80 | 0 | user_command($char); | |||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | 0 | my $left = ( $t_0 + $duration - time() ); | |||||||||||||||||||||||||||||||
| 85 | 0 | my $hours = int( $left / 3600 ); | |||||||||||||||||||||||||||||||
| 86 | 0 | my $minutes = int( ( $left - $hours * 3600 ) / 60 ); | |||||||||||||||||||||||||||||||
| 87 | 0 | my $seconds = $left - $hours * 3600 - $minutes * 60; | |||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | 0 | print sprintf( "%02d:%02d:%02d", $hours, $minutes, $seconds ); | |||||||||||||||||||||||||||||||
| 90 | 0 | print "\r"; | |||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | #sleep(1); | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||
| 95 | 0 | ReadMode('normal'); | |||||||||||||||||||||||||||||||
| 96 | 0 | $| = 0; | |||||||||||||||||||||||||||||||
| 97 | 0 | print "\n\nGO!\n"; | |||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | sub timestamp { | ||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | my ( | ||||||||||||||||||||||||||||||||
| 104 | 24 | ▶ | $Sekunden, $Minuten, $Stunden, $Monatstag, $Monat, | ||||||||||||||||||||||||||||||
|
Subroutine
timestamp: called CC=6 SCAR=18.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 105 | $Jahr, $Wochentag, $Jahrestag, $Sommerzeit | ||||||||||||||||||||||||||||||||
| 106 | ) = localtime(time); | ||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | 24 | $Monat += 1; | |||||||||||||||||||||||||||||||
| 109 | 24 | $Jahrestag += 1; | |||||||||||||||||||||||||||||||
| 110 | 24 | ▶ | $Monat = $Monat < 10 ? $Monat = "0" . $Monat : $Monat; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 111 | 24 | ▶ | $Monatstag = $Monatstag < 10 ? $Monatstag = "0" . $Monatstag : $Monatstag; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 112 | 24 | ▶ | $Stunden = $Stunden < 10 ? $Stunden = "0" . $Stunden : $Stunden; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 113 | 24 | ▶ | $Minuten = $Minuten < 10 ? $Minuten = "0" . $Minuten : $Minuten; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 114 | 24 | ▶ | $Sekunden = $Sekunden < 10 ? $Sekunden = "0" . $Sekunden : $Sekunden; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 115 | 24 | $Jahr += 1900; | |||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | 24 | return "$Monatstag.$Monat.$Jahr", "$Stunden:$Minuten:$Sekunden"; | |||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | sub user_command { | ||||||||||||||||||||||||||||||||
| 122 | my $cmd = shift; | ||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | print "test user_command = $cmd\n"; | ||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | # do something; | ||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | sub seconds2time { | ||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | my $duration = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
seconds2time: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||
| 132 | 0 | my $hours = int( $duration / 3600 ); | |||||||||||||||||||||||||||||||
| 133 | 0 | my $minutes = int( ( $duration - $hours * 3600 ) / 60 ); | |||||||||||||||||||||||||||||||
| 134 | 0 | my $seconds = $duration - $hours * 3600 - $minutes * 60; | |||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | 0 | my $formated = $hours . "h " . $minutes . "m " . $seconds . "s "; | |||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||
| 138 | 0 | return $formated; | |||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | 8 | 1; | |||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||
| 143 | __END__ | ||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||
| 145 | =pod | ||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||
| 147 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||
| 151 | Lab::XPRESS::Utilities - Global utility functions for XPRESS | ||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | =head1 VERSION | ||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | version 3.881 | ||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||
| 157 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||
| 159 | This software is copyright (c) 2023 by the Lab::Measurement team; in detail: | ||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||
| 161 | Copyright 2012 Stefan Geissler | ||||||||||||||||||||||||||||||||
| 162 | 2013 Andreas K. Huettel | ||||||||||||||||||||||||||||||||
| 163 | 2016 Simon Reinhardt | ||||||||||||||||||||||||||||||||
| 164 | 2017 Andreas K. Huettel | ||||||||||||||||||||||||||||||||
| 165 | 2020 Andreas K. Huettel | ||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||
| 168 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||
| 169 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||
| 171 | =cut | ||||||||||||||||||||||||||||||||