Lab::Moose::Instrument::Cache - Role for device cache functionality in Moose::Instrument drivers.
in your driver:
use Lab::Moose::Instrument::Cache; cache 'foobar' => (getter => 'get_foobar'); sub get_foobar { my $self = shift; return $self->cached_foobar( $self->query(command => ...)); } sub set_foobar { my ($self, $value) = @_; $self->write(command => ...); $self->cached_foobar($value); }
This package exports a new Moose keyword: cache.
Calling cache key => (getter => $getter, isa => $type) will generate a Moose attribute 'cached_key' with the following properties:
cache key => (getter => $getter, isa => $type)
is => 'rw', isa => $type, predicate => 'has_cached_key', clearer => 'clear_cached_key', builder => 'cached_key_builder', lazy => 1, init_arg => undef
The isa argument is optional.
isa
The builder method comes into play if a cache entry is in the cleared state. If the getter is called in this situation, the builder method will be used to generate the value. The default builder method just calls the configured $getter method.
$getter
If you need to call the getter with specific arguments, override the builder method. For example, the format_data_query of the Lab::Moose::Instrument::RS_ZVM needs a timeout of 3s. This is done by putting the following into the driver:
format_data_query
sub cached_format_data_builder { my $self = shift; return $self->format_data_query( timeout => 3 ); }
To install Lab::Measurement, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Lab::Measurement
CPAN shell
perl -MCPAN -e shell install Lab::Measurement
For more information on module installation, please visit the detailed CPAN module installation guide.