use warnings;
use strict;
use JSON;
use Plack::Request;
use Proc::ProcessTable;
sub {
my $req = Plack::Request->new(+shift);
my %pids = map { $_ => 1 } $req->path =~ /(\d+)/g;
my $procs = Proc::ProcessTable->new;
my $json = JSON->new;
my %status;
for my $proc ( @{ $procs->table } )
{
next if scalar(%pids) and not $pids{$proc->pid};
for my $field ( $procs->fields )
{
$status{$proc->pid}{$field} = $proc->$field;
}
}
return [ 200,
[ "Content-Type" => "application/json" ],
[ $json->pretty->encode(\%status) ]
];
};
####
my %pids = map { $_ => 1 } $req->path =~ /(\d+)/g;
####
next if scalar(%pids) and not $pids{$proc->pid};
####
my %hash = (
fred => flintstone,
wilma => flintstone,
barney => ruble,
);
print scalar(%hash) . "\n";