AquariumHive
view release on metacpan or search on metacpan
lib/App/AquariumHive.pm view on Meta::CPAN
mount '/'.$mount, $self->web_mounts->{$mount};
}
mount '/tile' => sub {
my ( $tile ) = $_[0]->{PATH_INFO} =~ m!/(.*)!;
if ($self->tile($tile)) {
return [ 200, [ "Content-Type" => "application/json" ], [encode_json({
html => $self->tile($tile)->html,
$self->tile($tile)->has_js ? ( js => $self->tile($tile)->js ) : (),
})] ];
} else {
return [ 404, [ "Content-Type" => "application/json" ], [encode_json({
not => 'found',
})] ];
}
};
mount '/name' => sub {
return [ 200, [ "Content-Type" => "application/json" ], ['"'.$self->name.'"'] ];
};
mount '/tiles' => sub {
return [ 200, [ "Content-Type" => "application/json" ], [encode_json([sort { $a cmp $b } keys %{$self->tiles}])] ];
};
mount '/' => builder {
enable 'Rewrite',
rules => sub { s{^/$}{/index.html}; };
enable "Plack::Middleware::Static",
path => qr{^/},
root => $self->web_root;
};
});
return $server;
}
sub command_aqhive {
my ( $self, $command, @args ) = @_;
return unless defined $command;
my $hivejso;
if ($self->simulation) {
$hivejso = HiveJSO->new(
unit => 'rasputin',
command => scalar @args ? ([ $command, @args ]) : ($command),
)->hivejso_short;
} else {
$hivejso = encode_json({
o => scalar @args ? ([ $command, @args ]) : ($command),
});
}
$self->debug('HiveJSO OUT '.$hivejso);
$self->uart->push_write($hivejso);
}
sub run {
my ( $self ) = @_;
$self->plugins;
$self->web;
$self->uart;
$self->db;
$self->info("Starting App::AquariumHive (port ".$self->port.")...");
my $t = AE::timer 0, 15, sub { $self->command_aqhive('data') };
AE::cv->recv;
}
sub run_cmd {
my ( $self, $command ) = @_;
my @lines;
if ($command) {
require IPC::Open3; # core
# autoflush STDOUT so we can see command output right away
local $| = 1;
# combine stdout and stderr for ease of proxying through the logger
my $pid = IPC::Open3::open3(my ($in, $out), undef, $command);
while(defined(my $line = <$out>)){
chomp($line);
push @lines, $line;
}
# zombie repellent
waitpid($pid, 0);
my $status = ($? >> 8);
}
return @lines;
}
1;
__END__
=pod
=head1 NAME
App::AquariumHive - Temporary Daemon - will later be replaced by HiveHub
=head1 VERSION
version 0.003
=head1 DESCRIPTION
B<IN DEVELOPMENT, DO NOT USE YET>
See L<http://aquariumhive.com/> for now.
=head1 SUPPORT
IRC
Join #AquariumHive on irc.freenode.net. Highlight Getty for fast reaction :).
Repository
https://github.com/homehivelab/aquariumhive
Pull request and additional contributors are welcome
Issue Tracker
https://github.com/homehivelab/aquariumhive/issues
=head1 AUTHOR
( run in 1.532 second using v1.01-cache-2.11-cpan-d8267643d1d )