Moose/Instrument/Zhinst.pm

filter: Statementstmt 96.1% 50 / 52 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 100% 4 / 4 totaltotal 94.4% 68 / 72 CC 3 SCAR 3.8
CC
3
Cov
93%
_get_device
3.2
BEGIN
1.0
BEGIN
1.0
CRAP 1.5
« Moose/Instrument/SCPI/Sense/Function/Concurrent.pm ↑ Summary Moose/Instrument/OI_Common.pm »
1 package Lab::Moose::Instrument::Zhinst;
2 3 $Lab::Moose::Instrument::Zhinst::VERSION = '3.931';
3 #ABSTRACT: Base class for Zurich Instruments device drivers
4  
5 3 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use MooseX::Params::Validate qw/validated_list validated_hash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # do not make imported functions available as methods.
12 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use YAML::XS 'Dump';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # FIXME: put this into separate module?
16 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ZI_LIST_NODES_RECURSIVE => 1,
18 ZI_LIST_NODES_ABSOLUTE => 2,
19 3 };
20  
21 3 extends 'Lab::Moose::Instrument';
22  
23 3 has device => (
24 is => 'ro',
25 isa => 'Str',
26 builder => '_get_device',
27 lazy => 1,
28 );
29  
30  
31 2 ▶sub _get_device {
Subroutine _get_device: called CC=3 SCAR=11.5
32 2 my $self = shift;
33  
34 2 my $nodes = $self->list_nodes(
35 path => '/',
36 mask => ZI_LIST_NODES_ABSOLUTE | ZI_LIST_NODES_RECURSIVE
37 );
38  
39 2 my @devices = $nodes =~ m{^/dev\w*}gmi;
40 2 my %hash = map { $_ => 1 } @devices;
41 2 @devices = keys %hash;
42 2 ▶ if ( @devices == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@devices == 0) 0 2 2
43 0 croak "no connected devices";
44 }
45 2 ▶ if ( @devices > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@devices > 1) 0 2 2
46 0 croak
47 "found multiple devices: @devices. Give explicit device argument.";
48 }
49 2 return $devices[0];
50 }
51  
52  
53 2 ▶sub list_nodes {
Subroutine list_nodes: called CC=1 SCAR=0.0
Pod documented
54 2 my ( $self, %args ) = validated_hash(
55 \@_,
56  
57 # Proper validation is done in Connection::Zhinst.
58 path => { isa => 'Str' },
59 mask => { isa => 'Int' },
60 );
61  
62 2 $args{method} = 'ListNodes';
63 2 my $command = Dump( \%args );
64 2 return $self->binary_query( command => $command );
65 }
66  
67  
68 3 ▶sub get_value {
Subroutine get_value: called CC=1 SCAR=0.0
Pod documented
69 3 my ( $self, %args ) = validated_hash(
70 \@_,
71 path => { isa => 'Str' },
72 type => { isa => 'Str' },
73 );
74  
75 3 $args{method} = 'Get';
76 3 my $command = Dump( \%args );
77 3 return $self->binary_query( command => $command );
78 }
79  
80  
81 2 ▶sub sync_set_value {
Subroutine sync_set_value: called CC=1 SCAR=0.0
Pod documented
82 2 my ( $self, %args ) = validated_hash(
83 \@_,
84 path => { isa => 'Str' },
85 type => { isa => 'Str' },
86 value => { isa => 'Str' },
87 );
88  
89 2 $args{method} = 'SyncSet';
90 2 my $command = Dump( \%args );
91 2 return $self->binary_query( command => $command );
92 }
93  
94  
95 1 ▶sub sync_poll {
Subroutine sync_poll: called CC=1 SCAR=0.0
Pod documented
96 1 my ( $self, %args ) = validated_hash(
97 \@_,
98 path => { isa => 'Str' },
99 timeout => { isa => 'Num', optional => 1 },
100 );
101 1 $args{method} = 'SyncPoll';
102 1 my $command = Dump( \%args );
103 1 return $self->binary_query( command => $command );
104 }
105  
106 3 __PACKAGE__->meta->make_immutable();
107  
108 3 1;
109  
110 __END__
« Moose/Instrument/SCPI/Sense/Function/Concurrent.pm ↑ Summary Moose/Instrument/OI_Common.pm »