line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lab::Moose::Sweep::Continuous::Time; |
2
|
|
|
|
|
|
|
$Lab::Moose::Sweep::Continuous::Time::VERSION = '3.880'; |
3
|
|
|
|
|
|
|
#ABSTRACT: Time sweep |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
3286
|
use v5.20; |
|
2
|
|
|
|
|
8
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
12
|
use Moose; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
18
|
|
9
|
2
|
|
|
2
|
|
15887
|
use Time::HiRes qw/time sleep/; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
20
|
|
10
|
2
|
|
|
2
|
|
307
|
use Carp; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
1091
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
extends 'Lab::Moose::Sweep::Continuous'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# Public attributes |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has [qw/ +instrument +points +rates/] => ( required => 0 ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has duration => ( is => 'ro', isa => 'Lab::Moose::PosNum' ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has durations => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
isa => 'ArrayRef[Lab::Moose::PosNum]', |
25
|
|
|
|
|
|
|
traits => ['Array'], |
26
|
|
|
|
|
|
|
handles => { |
27
|
|
|
|
|
|
|
get_duration => 'get', shift_durations => 'shift', |
28
|
|
|
|
|
|
|
num_durations => 'count', durations_array => 'elements', |
29
|
|
|
|
|
|
|
}, |
30
|
|
|
|
|
|
|
writer => '_durations' |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# TODO: make duration optional => infinite |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub BUILD { |
36
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Do not mess with intervals/durations attribute arrays. Make copies of them. |
39
|
1
|
|
|
|
|
3
|
my @intervals; |
40
|
|
|
|
|
|
|
my @durations; |
41
|
|
|
|
|
|
|
|
42
|
1
|
50
|
|
|
|
33
|
if ( defined $self->interval ) { |
|
|
0
|
|
|
|
|
|
43
|
1
|
50
|
|
|
|
33
|
if ( defined $self->intervals ) { |
44
|
0
|
|
|
|
|
0
|
croak "Use either interval or intervals attribute"; |
45
|
|
|
|
|
|
|
} |
46
|
1
|
|
|
|
|
30
|
@intervals = ( $self->interval ); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
elsif ( defined $self->intervals ) { |
49
|
0
|
|
|
|
|
0
|
@intervals = $self->intervals_array; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { |
52
|
|
|
|
|
|
|
# default interval |
53
|
0
|
|
|
|
|
0
|
@intervals = (0); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
1
|
50
|
|
|
|
32
|
if ( defined $self->duration ) { |
|
|
0
|
|
|
|
|
|
57
|
1
|
50
|
|
|
|
31
|
if ( defined $self->durations ) { |
58
|
0
|
|
|
|
|
0
|
croak "Use either duration or durations attribute"; |
59
|
|
|
|
|
|
|
} |
60
|
1
|
|
|
|
|
32
|
@durations = ( $self->duration ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
elsif ( defined $self->durations ) { |
63
|
0
|
|
|
|
|
0
|
@durations = $self->durations_array; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
0
|
|
|
|
|
0
|
croak "Missing mandatory duration or durations argument"; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
1
|
|
|
|
|
41
|
$self->_intervals( \@intervals ); |
70
|
1
|
|
|
|
|
37
|
$self->_durations( \@durations ); |
71
|
|
|
|
|
|
|
|
72
|
1
|
50
|
|
|
|
42
|
if ( $self->num_intervals < 1 ) { |
73
|
0
|
|
|
|
|
0
|
croak "need at least one interval"; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
1
|
50
|
|
|
|
38
|
if ( $self->num_intervals != $self->num_durations ) { |
77
|
0
|
|
|
|
|
0
|
croak "need same number of intervals and durations"; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub go_to_sweep_start { |
82
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
83
|
1
|
|
|
|
|
41
|
$self->reset_index(); |
84
|
1
|
|
|
|
|
62
|
$self->reset_points_index(); |
85
|
1
|
|
|
|
|
46
|
$self->inc_points_index(); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub start_sweep { |
89
|
1
|
|
|
1
|
0
|
34
|
my $self = shift; |
90
|
1
|
|
|
|
|
53
|
$self->_start_time( time() ); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub sweep_finished { |
94
|
7
|
|
|
7
|
0
|
20
|
my $self = shift; |
95
|
|
|
|
|
|
|
|
96
|
7
|
|
|
|
|
291
|
my $duration = $self->get_duration( $self->points_index - 1 ); |
97
|
|
|
|
|
|
|
|
98
|
7
|
100
|
|
|
|
347
|
if ( time() - $self->start_time < $duration ) { |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# still in duration |
101
|
6
|
|
|
|
|
30
|
return 0; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# duration is finished. |
105
|
1
|
|
|
|
|
75
|
$self->inc_points_index(); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# Are there more durations? |
108
|
1
|
50
|
|
|
|
59
|
if ( $self->points_index < $self->num_durations() ) { |
109
|
0
|
|
|
|
|
0
|
$self->reset_index(); |
110
|
0
|
|
|
|
|
0
|
$self->start_sweep(); |
111
|
0
|
|
|
|
|
0
|
return 0; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
else { |
114
|
1
|
|
|
|
|
12
|
return 1; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub get_value { |
119
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
120
|
0
|
|
|
|
|
|
return time(); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=pod |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=encoding UTF-8 |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 NAME |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Lab::Moose::Sweep::Continuous::Time - Time sweep |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 VERSION |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
version 3.880 |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 SYNOPSIS |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
use Lab::Moose; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
my $sweep = sweep( |
145
|
|
|
|
|
|
|
type => 'Continuous::Time', |
146
|
|
|
|
|
|
|
interval => 0.5, # optional, default is 0 (no delay) |
147
|
|
|
|
|
|
|
duration => 60 |
148
|
|
|
|
|
|
|
); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
# Multiple segments with different intervals |
151
|
|
|
|
|
|
|
my $sweep = sweep( |
152
|
|
|
|
|
|
|
type => 'Continuous::Time', |
153
|
|
|
|
|
|
|
# 60s with 0.5s interval followed by 120s with 1s interval |
154
|
|
|
|
|
|
|
durations => [60, 120], |
155
|
|
|
|
|
|
|
intervals => [0.5, 1], |
156
|
|
|
|
|
|
|
); |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
This software is copyright (c) 2023 by the Lab::Measurement team; in detail: |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Copyright 2018 Simon Reinhardt |
163
|
|
|
|
|
|
|
2020 Andreas K. Huettel, Simon Reinhardt |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
167
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |