Moose/Instrument/AdjustRange.pm

filter: Statementstmt 42.5% 17 / 40 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 100% 1 / 1 totaltotal 40.3% 23 / 57 CC 7 SCAR 35.0
CC
7
Cov
34%
adjust_measurement_range
56.0
BEGIN
1.0
BEGIN
1.0
CRAP 33.1
« Moose/Sweep/Continuous.pm ↑ Summary Moose/Connection/Zhinst.pm »
1 package Lab::Moose::Instrument::AdjustRange;
2 2 $Lab::Moose::Instrument::AdjustRange::VERSION = '3.931';
3 #ABSTRACT: Role for automatic adjustment of measurement ranges.
4  
5 2 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Lab::Moose::Instrument 'setter_params';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 requires qw/allowed_ranges set_range get_cached_range/;
14  
15  
16 0 ▶sub adjust_measurement_range {
Subroutine adjust_measurement_range: not called CC=7 SCAR=40.3
Pod documented
17 0 my $self = shift;
18 0 my ( $value, $verbose, $ranges, $safety_factor ) = validated_list(
19 \@_,
20 value => { isa => 'Num' },
21 verbose => { isa => 'Bool', default => 1 },
22 ranges => { isa => 'ArrayRef[Num]', optional => 1 },
23 safety_factor => { isa => 'Num', default => 1 },
24 );
25  
26 0 $value = abs($value);
27  
28 0 my @ranges;
29 0 ▶ if ( defined $ranges ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ranges) { } 0 0 0
30 0 @ranges = @{$ranges};
31 }
32 else {
33 0 @ranges = @{ $self->allowed_ranges };
34 }
35  
36 0 @ranges = sort @ranges; # ascending order
37  
38 0 my $current_range = $self->get_cached_range();
39 0 my $new_range;
40  
41 0 for my $range (@ranges) {
42 0 ▶ if ( $value <= $safety_factor * $range ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value <= $safety_factor * $range) 0 0 0
43 0 $new_range = $range;
44 0 last;
45 }
46 }
47  
48 0 ▶ if ( not defined $new_range ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $new_range) 0 0 0
49  
50 # use maximum range
51 0 $new_range = $ranges[-1];
52 }
53  
54 0 ▶ if ( $new_range != $current_range ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_range != $current_range) 0 0 0
55 0 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 0 0
56 0 carp
57 "Adjusting range from $current_range to $new_range (current value: $value)";
58 }
59 0 $self->set_range( value => $new_range );
60 }
61 0 return $current_range;
62 }
63  
64  
65 2 1;
66  
67 __END__
« Moose/Sweep/Continuous.pm ↑ Summary Moose/Connection/Zhinst.pm »