Lab-Measurement
view release on metacpan or search on metacpan
lib/Lab/Moose.pm view on Meta::CPAN
package Lab::Moose;
$Lab::Moose::VERSION = '3.931';
#ABSTRACT: Convenient loaders and constructors for L<Lab::Moose::Instrument>, L<Lab::Moose::Sweep>, L<Lab::Moose::DataFolder> and L<Lab::Moose::DataFile>
use v5.20;
use warnings;
use strict;
use MooseX::Params::Validate;
use Moose::Util::TypeConstraints qw/subtype as where message coerce from via/;
use Module::Load;
use Lab::Moose::Connection;
use Lab::Moose::DataFolder;
use Carp;
our @ISA = qw(Exporter);
# FIXME: export 'use warnings; use strict; into caller'
our @EXPORT
= qw/instrument datafolder datafile linspace sweep sweep_datafile/;
# Enable "use warnings; use strict" in caller.
# See https://www.perlmonks.org/?node_id=1095522
# and https://metacpan.org/pod/Import::Into
sub import {
__PACKAGE__->export_to_level( 1, @_ );
strict->import();
warnings->import();
}
sub instrument {
my %args = validated_hash(
\@_,
type => { isa => 'Str', optional => 1 },
MX_PARAMS_VALIDATE_ALLOW_EXTRA => 1,
);
my $type = delete $args{type};
if ( defined $type ) {
$type = "Lab::Moose::Instrument::$type";
}
else {
$type = "Lab::Moose::Instrument";
}
load $type;
return $type->new(%args);
}
sub datafolder {
return Lab::Moose::DataFolder->new(@_);
}
sub datafile {
my (%args) = validated_hash(
\@_,
type => { isa => 'Str', default => 'Gnuplot' },
MX_PARAMS_VALIDATE_ALLOW_EXTRA => 1
);
my $type = delete $args{type};
$type = "Lab::Moose::DataFile::$type";
load $type;
return $type->new(%args);
}
sub linspace {
my ( $from, $to, $step, $exclude_from ) = validated_list(
\@_,
from => { isa => 'Num' },
to => { isa => 'Num' },
step => { isa => 'Num' },
exclude_from => { isa => 'Bool', default => 0 },
);
$step = abs($step);
my $sign = $to > $from ? 1 : -1;
my @steps;
for ( my $i = $exclude_from ? 1 : 0;; ++$i ) {
my $point = $from + $i * $sign * $step;
( run in 1.521 second using v1.01-cache-2.11-cpan-39bf76dae61 )