Moose.pm

filter: Statementstmt 94.8% 74 / 78 Branchbran 80.0% 8 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 20 / 22 Podpod 100% 6 / 6 totaltotal 93.1% 108 / 116 CC 6 SCAR 4.8
CC
6
Cov
93%
linspace
4.0
INIT
2.1
instrument
2.0
CRAP 1.6
« Moose/Instrument/HP33120A.pm ↑ Summary Moose/DataFile/Gnuplot/Compressed.pm »
1 package Lab::Moose;
2 27 $Lab::Moose::VERSION = '3.931';
3 #ABSTRACT: Convenient loaders and constructors for L<Lab::Moose::Instrument>, L<Lab::Moose::Sweep>, L<Lab::Moose::DataFolder> and L<Lab::Moose::DataFile>
4  
5 27 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 27 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 27 ▶use Moose::Util::TypeConstraints qw/subtype as where message coerce from via/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 27 ▶use Module::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 27 ▶use Lab::Moose::Connection;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 27 ▶use Lab::Moose::DataFolder;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 27 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 27 our @ISA = qw(Exporter);
18  
19 # FIXME: export 'use warnings; use strict; into caller'
20  
21 our @EXPORT
22 27 = qw/instrument datafolder datafile linspace sweep sweep_datafile/;
23  
24  
25 # Enable "use warnings; use strict" in caller.
26 # See https://www.perlmonks.org/?node_id=1095522
27 # and https://metacpan.org/pod/Import::Into
28  
29 43 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
30 43 __PACKAGE__->export_to_level( 1, @_ );
31 43 strict->import();
32 43 warnings->import();
33 }
34  
35 31 ▶sub instrument {
Subroutine instrument: called CC=2 SCAR=7.1
Pod documented
36 31 my %args = validated_hash(
37 \@_,
38 type => { isa => 'Str', optional => 1 },
39 MX_PARAMS_VALIDATE_ALLOW_EXTRA => 1,
40 );
41  
42 31 my $type = delete $args{type};
43 31 ▶ if ( defined $type ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type) { } 31 0 31
44 31 $type = "Lab::Moose::Instrument::$type";
45 }
46 else {
47 0 $type = "Lab::Moose::Instrument";
48 }
49 31 load $type;
50  
51 31 return $type->new(%args);
52 }
53  
54  
55 73 ▶sub datafolder {
Subroutine datafolder: called CC=1 SCAR=0.0
Pod documented
56 73 return Lab::Moose::DataFolder->new(@_);
57 }
58  
59  
60 37 ▶sub datafile {
Subroutine datafile: called CC=1 SCAR=0.0
Pod documented
61 37 my (%args) = validated_hash(
62 \@_,
63 type => { isa => 'Str', default => 'Gnuplot' },
64 MX_PARAMS_VALIDATE_ALLOW_EXTRA => 1
65 );
66  
67 37 my $type = delete $args{type};
68  
69 37 $type = "Lab::Moose::DataFile::$type";
70  
71 37 load $type;
72  
73 37 return $type->new(%args);
74 }
75  
76  
77 188 ▶sub linspace {
Subroutine linspace: called CC=4 SCAR=13.9
Pod documented
78 188 my ( $from, $to, $step, $exclude_from ) = validated_list(
79 \@_,
80 from => { isa => 'Num' },
81 to => { isa => 'Num' },
82 step => { isa => 'Num' },
83 exclude_from => { isa => 'Bool', default => 0 },
84 );
85  
86 188 $step = abs($step);
87 188 ▶ my $sign = $to > $from ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$to > $from ? : 114 74 188
88  
89 188 my @steps;
90 188 ▶ for ( my $i = $exclude_from ? 1 : 0;; ++$i ) {
Branch: 1 branch
BranchTrueFalseTotal
$exclude_from ? : 170 18 188
91 277 my $point = $from + $i * $sign * $step;
92 277 ▶ if ( ( $point - $to ) * $sign >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($point - $to) * $sign >= 0) 188 89 277
93 188 last;
94 }
95 89 push @steps, $point;
96 }
97 188 return ( @steps, $to );
98 }
99  
100  
101 20 ▶sub sweep {
Subroutine sweep: called CC=1 SCAR=0.0
Pod documented
102 20 my (%args) = validated_hash(
103 \@_,
104 type => { isa => 'Str' },
105 MX_PARAMS_VALIDATE_ALLOW_EXTRA => 1
106 );
107  
108 20 my $type = delete $args{type};
109  
110 20 $type = "Lab::Moose::Sweep::$type";
111  
112 20 load $type;
113  
114 20 return $type->new(%args);
115 }
116  
117 17 ▶sub sweep_datafile {
Subroutine sweep_datafile: called CC=1 SCAR=0.0
Pod documented
118 17 my (%args) = validated_hash(
119 \@_,
120 filename => { isa => 'Str', default => 'data' },
121 MX_PARAMS_VALIDATE_ALLOW_EXTRA => 1
122 );
123  
124 17 my $class = 'Lab::Moose::Sweep::DataFile';
125 17 load $class;
126 17 return $class->new( params => \%args );
127 }
128  
129 # Some often used subtypes
130  
131 subtype 'Lab::Moose::PosNum',
132 as 'Num',
133 43 ▶ where { $_ >= 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
134 0 ▶ message {"$_ is not a positive number"};
Subroutine __ANON__: not called CC=1 SCAR=1.2
135  
136 subtype 'Lab::Moose::PosInt',
137 as 'Int',
138 5 ▶ where { $_ >= 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
139 0 ▶ message {"$_ is not a positive integer number"};
Subroutine __ANON__: not called CC=1 SCAR=1.2
140  
141 27 subtype 'ArrayRefOfInstruments',
142 as 'ArrayRef[Lab::Moose::Instrument]';
143  
144 coerce 'ArrayRefOfInstruments',
145 17 ▶ from 'Lab::Moose::Instrument', via { [ $_ ] };
Subroutine __ANON__: called CC=1 SCAR=0.0
146  
147 26 ▶INIT {
Subroutine INIT: called CC=2 SCAR=7.6
148 26 my $percentage = 2;
149 26 my $message = "Please cite Lab::Measurement in your publications based on the measured data, \n" .
150 "e.g. in the acknowledgment section of the article. The reference is:\n" .
151 " S. Reinhard et al., Comp. Phys. Comm. 234, 216 (2019)\n" .
152 " doi:10.1016/j.cpc.2018.07.024\n\n";
153  
154 26 ▶ if( rand() < ($percentage / 100) ){
Branch: 1 branch
BranchTrueFalseTotal
if (rand() < $percentage / 100) 0 26 26
155 0 print $message;
156 };
157 };
158  
159 27 1;
160  
161 __END__
« Moose/Instrument/HP33120A.pm ↑ Summary Moose/DataFile/Gnuplot/Compressed.pm »