File Coverage

blib/lib/Lab/XPRESS/Sweep/Repeater.pm
Criterion Covered Total %
statement 11 33 33.3
branch 0 4 0.0
condition 0 3 0.0
subroutine 4 6 66.6
pod 1 2 50.0
total 16 48 33.3


line stmt bran cond sub pod time code
1             package Lab::XPRESS::Sweep::Repeater;
2             #ABSTRACT: Simple repeater
3             $Lab::XPRESS::Sweep::Repeater::VERSION = '3.881';
4 1     1   1689 use v5.20;
  1         4  
5              
6 1     1   6 use Lab::XPRESS::Sweep;
  1         2  
  1         26  
7 1     1   5 use Time::HiRes qw/usleep/, qw/time/;
  1         2  
  1         5  
8 1     1   113 use strict;
  1         2  
  1         333  
9              
10             our @ISA = ('Lab::XPRESS::Sweep');
11              
12             sub new {
13 0     0 0   my $proto = shift;
14 0           my @args = @_;
15 0   0       my $class = ref($proto) || $proto;
16             my $self->{default_config} = {
17 0           id => 'Repeater',
18             filename_extension => '#',
19             repetitions => 1,
20             stepwidth => 1,
21             points => [1],
22             rate => [1],
23             mode => 'list',
24             allowed_sweep_modes => ['list'],
25             backsweep => 0,
26             values => undef,
27             };
28              
29 0           $self = $class->SUPER::new( $self->{default_config}, @args );
30 0           bless( $self, $class );
31 0           $self->{config}->{points} = [1];
32 0           $self->{config}->{duration} = [1];
33              
34 0 0         if ( ref( $self->{config}->{repetitions} ) eq 'ARRAY' ) {
35 0           $self->{config}->{values} = $self->{config}->{repetitions};
36             $self->{config}->{repetitions}
37 0           = scalar @{ $self->{config}->{repetitions} };
  0            
38             }
39              
40 0           $self->{config}->{mode} = 'list';
41 0           $self->{loop}->{interval} = $self->{config}->{interval};
42              
43 0           $self->{DataFile_counter} = 0;
44              
45 0           $self->{DataFiles} = ();
46              
47 0           return $self;
48             }
49              
50             sub get_value {
51 0     0 1   my $self = shift;
52              
53 0 0         if ( defined $self->{config}->{values} ) {
54 0           return @{ $self->{config}->{values} }[ $self->{repetition} - 1 ];
  0            
55             }
56             else {
57 0           return $self->{repetition};
58             }
59             }
60              
61             1;
62              
63             __END__
64              
65             =pod
66              
67             =encoding UTF-8
68              
69             =head1 NAME
70              
71             Lab::XPRESS::Sweep::Repeater - Simple repeater
72              
73             =head1 VERSION
74              
75             version 3.881
76              
77             =head1 SYNOPSIS
78              
79             use Lab::XPRESS::hub;
80             my $hub = new Lab::XPRESS::hub();
81            
82            
83            
84             my $repeater = $hub->Sweep('Repeater',
85             {
86             repetitions => 5
87             });
88              
89             =head1 DESCRIPTION
90              
91             Parent: Lab::XPRESS::Sweep
92              
93             The Lab::XPRESS::Sweep::Repeater class implements a simple repeater module in the Lab::XPRESS::Sweep framework.
94              
95             =head1 CONSTRUCTOR
96              
97             my $repeater = $hub->Sweep('Repeater',
98             {
99             repetitions => 5
100             });
101              
102             Instantiates a new repeater with 5 repetitions. Alternatively
103              
104             my $repeater_array = $hub->Sweep('Repeater',
105             {
106             repetitions => [10, 20, 30, 40, 50]
107             });
108              
109             Instantiates also a repeater with 5 repetitions. However, the function
110              
111             $repeater->get_value(); # <-- returns 1,2,3,4,5 depending on the repetition,
112             $repeater->get_array(); # <-- returns 10,20,30,40,50 depending on the repetition.
113             .
114              
115             =head1 PARAMETERS
116              
117             =head2 repetitions [int / array] (default = 1)
118              
119             number of repetitions. default value is 1, negative values indicate a infinit number of repetitions.
120             When an array is given, the number of reetitions corresponds to the length of the array.
121              
122             =head2 id [string] (default = 'Repeater')
123              
124             Just an ID.
125              
126             =head2 filename_extention [string] (default = '#=')
127              
128             Defines a postfix, that will be appended to the filenames if necessary.
129              
130             =head2 delay_before_loop [float] (default = 0)
131              
132             defines the time in seconds to wait after the starting point has been reached.
133              
134             =head2 delay_in_loop [float] (default = 0)
135              
136             This parameter is relevant only if mode = 'step' or 'list' has been selected.
137             Defines the time in seconds to wait after the value for the next step has been reached.
138              
139             =head2 delay_after_loop [float] (default = 0)
140              
141             Defines the time in seconds to wait after the sweep has been finished. This delay will be executed before an optional backsweep or optional repetitions of the sweep.
142              
143             =head1 METHODS
144              
145             =head2 get_value()
146              
147             Returns an integer number n corresponding to the nth repetition or if an array @a was given for the parameter 'repetitions' it returns @a[n].
148              
149             =head1 CAVEATS/BUGS
150              
151             probably none
152              
153             =head1 SEE ALSO
154              
155             =over 4
156              
157             =item L<Lab::XPRESS::Sweep>
158              
159             =back
160              
161             =head1 COPYRIGHT AND LICENSE
162              
163             This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
164              
165             Copyright 2012 Stefan Geissler
166             2013 Andreas K. Huettel, Christian Butschkow, Stefan Geissler
167             2015 Christian Butschkow
168             2016 Simon Reinhardt
169             2017 Andreas K. Huettel
170             2020 Andreas K. Huettel
171              
172              
173             This is free software; you can redistribute it and/or modify it under
174             the same terms as the Perl 5 programming language system itself.
175              
176             =cut