Dumper;
use JSON;
use RPi::WiringPi;
use RPi::Const qw(:all);
use WiringPi::API qw(:perl);
my $pi = RPi::WiringPi->new;
my $pin_num = 2;
my $j = $ENV{RPI_PINS};
my $p = $j ? decode_json $j : {};
die "pin in use...\n";
}
$p->{$pin_num}{alt} = $pi->get_alt($pin_num);
$p->{$pin_num}{state} = $pi->read_pin($pin_num);
print Dumper $p;
$j = encode_json $p;
say $j;
$ENV{RPI_PINS} = $j;
iringPi::Meta;
use strict;
use warnings;
use Carp qw(croak);
use IPC::ShareLite qw(:flock);
use JSON::XS;
our $VERSION = '2.3633_03';
sub meta {
my ($self) = @_;
return $self->{meta_shm}
}
sub meta_fetch {
my ($self) = @_;
my $json;
$json = $self->meta->fetch;
$json = "{}" if $json eq '';
my $perl = decode_json $json;
return $perl
}
sub meta_store {
my ($s
croak "meta_store() requires a hash reference sent in...\n";
}
$self->meta->store(encode_json $data) or die $!;
}
sub meta_delete {
my ($self, $name) = @_;
if (! defined $name){
strict;
use Benchmark qw(timethis timethese cmpthese);
use Data::Dumper;
use IPC::ShareLite;
use JSON::XS;
use Storable qw(freeze thaw);
die "need run count" if ! $ARGV[0];
my $s = IPC::ShareLite->
/data';
cmpthese $ARGV[0], {
json_file => \&json_file,
json_share => \&json_share,
stor_file => \&stor_file,
stor_share => \&stor_share,
};
sub json_file {
my $p = {a => 1, b =>
$fh, '>', $f or die $!;
print $fh encode_json($p);
close $fh;
{
local $/;
open $fh, '<', $f or die $!;
$p = decode_json <$fh>;
close $fh;
}
open $f
use warnings;
use strict;
use Data::Dumper;
use IPC::ShareLite;
use JSON::XS;
my $s = IPC::ShareLite->new(
-key => 1235,
-create => 1,
-destroy => 0,
) or die "can't create share: $