| 1 | package Lab::MultiChannelInstrument::DeviceCache; | ||
| 2 | #ABSTRACT: Multi-channel instrument device cache | ||
| 3 | $Lab::MultiChannelInstrument::DeviceCache::VERSION = '3.899'; | ||
| 4 | use v5.20; | ||
| 5 | |||
| 6 | use warnings; | ||
| 7 | use strict; | ||
| 8 | |||
| 9 | require Tie::Hash; | ||
| 10 | use List::MoreUtils qw{ any }; | ||
| 11 | |||
| 12 | |||
| 13 | our @ISA = 'Tie::ExtraHash'; | ||
| 14 | |||
| 15 | sub TIEHASH { | ||
| 16 | my $class = shift; | ||
| 17 | my $storage = bless [ {}, @_ ], $class; | ||
| 18 | return $storage; | ||
| 19 | } | ||
| 20 | |||
| 21 | sub STORE { | ||
| 22 | $_[0][0]{ $_[1] } = $_[2]; | ||
| 23 | if ( any { $_[1] eq $_ } @{ $_[0][1]->{multichannel_shared_cache} } ) { | ||
| 24 | $_[0][1]->device_cache( { $_[1] => $_[2] } ); | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | sub FETCH { | ||
| 29 | |||
| 30 | if ( any { $_[1] eq $_ } @{ $_[0][1]->{multichannel_shared_cache} } ) { | ||
| 31 | return $_[0][1]->device_cache( $_[1] ); | ||
| 32 | } | ||
| 33 | else { | ||
| 34 | return $_[0][0]{ $_[1] }; | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | sub EXISTS { | ||
| 39 | if ( any { $_[1] eq $_ } @{ $_[0][1]->{multichannel_shared_cache} } ) { | ||
| 40 | return exists $_[0][1]->{device_cache}->{ $_[1] }; | ||
| 41 | } | ||
| 42 | return exists $_[0][0]->{ $_[1] }; | ||
| 43 | } | ||
| 44 | |||
| 45 | 1; | ||
| 46 | |||
| 47 | __END__ |