Lab-Measurement
view release on metacpan or search on metacpan
lib/Lab/Moose/Sweep.pm view on Meta::CPAN
use Moose;
use MooseX::StrictConstructor;
use Moose::Util::TypeConstraints 'enum';
use MooseX::Params::Validate;
use Lab::Moose::Sweep::DataFile;
use Lab::Moose::Countdown 'countdown';
use Data::Dumper;
# Do not import all functions as they clash with the attribute methods.
use Lab::Moose::Catfile qw/our_catfile/;
use Carp;
#
# Public attributes set by the user
#
has filename_extension => ( is => 'ro', isa => 'Str', default => 'Value=' );
has delay_before_loop => ( is => 'ro', isa => 'Num', default => 0 );
has delay_in_loop => ( is => 'ro', isa => 'Num', default => 0 );
has delay_after_loop => ( is => 'ro', isa => 'Num', default => 0 );
has before_loop => (
is => 'ro',
isa => 'CodeRef',
default => sub {
sub { }
}
);
has after_loop => (
is => 'ro',
isa => 'CodeRef',
default => sub {
sub { }
}
);
#
# Private attributes used internally
#
has slave => (
is => 'ro', isa => 'Lab::Moose::Sweep', init_arg => undef,
writer => '_slave'
);
has is_slave =>
( is => 'ro', isa => 'Bool', init_arg => undef, writer => '_is_slave' );
has datafile_params => (
is => 'ro',
isa => 'ArrayRef[Lab::Moose::Sweep::DataFile]', init_arg => undef,
writer => '_datafile_params'
);
has foldername =>
( is => 'ro', isa => 'Str', init_arg => undef, writer => '_foldername' );
# real Lab::Moose::DataFile
has datafiles => (
is => 'ro', isa => 'HashRef[Lab::Moose::DataFile]', init_arg => undef,
writer => '_datafiles'
);
has logged_datafiles => (
is => 'ro', isa => 'HashRef[Bool]', init_arg => undef,
writer => '_logged_datafiles'
);
has create_datafile_blocks => (
is => 'ro', isa => 'Bool', init_arg => undef,
writer => '_create_datafile_blocks'
);
# Should this sweep create a new datafile for each measurement point?
has create_datafiles => (
is => 'ro',
isa => 'Bool', init_arg => undef, writer => '_create_datafiles'
);
has datafolder => (
is => 'ro',
isa => 'Lab::Moose::DataFolder',
init_arg => undef,
writer => '_datafolder'
);
has measurement => (
is => 'ro', isa => 'CodeRef', init_arg => undef, writer => '_measurement',
predicate => 'has_measurement',
);
#
has was_used => (
is => 'ro', isa => 'Bool', init_arg => undef, default => 0,
writer => '_was_used'
);
sub _ensure_no_slave {
my $self = shift;
if ( $self->is_slave() ) {
croak "cannot do this with slave";
}
}
sub _ensure_sweeps_different {
my $self = shift;
my @sweeps = @_;
my %h = map { ( $_ + 0 ) => 1 } (@sweeps);
my @keys = keys %h;
if ( @keys != @sweeps ) {
croak "all sweeps must be separate objects!";
}
}
sub _add_plots {
my $self = shift;
my $datafile = shift;
my $handle = shift;
my @plots = @{ $handle->plots };
for my $plot_params (@plots) {
$datafile->add_plot($plot_params);
}
}
( run in 0.549 second using v1.01-cache-2.11-cpan-39bf76dae61 )