Developer-Dashboard
view release on metacpan or search on metacpan
lib/Developer/Dashboard/RuntimeManager.pm view on Meta::CPAN
package Developer::Dashboard::RuntimeManager;
use strict;
use warnings;
our $VERSION = '4.16';
use Capture::Tiny qw(capture);
use File::Spec;
use IO::Socket::INET;
use POSIX qw(close setsid strftime);
use Time::HiRes qw(sleep time);
use Developer::Dashboard::Collector;
use Developer::Dashboard::CollectorRunner ();
use Developer::Dashboard::InternalCLI ();
use Developer::Dashboard::JSON qw(json_encode json_decode);
use Developer::Dashboard::Platform qw(command_in_path is_windows);
our $SIGNAL_MANAGER;
our $COLLECTOR_SUPERVISOR_MANAGER;
# new(%args)
# Constructs the runtime lifecycle manager.
# Input: config, files, paths, runner, and app_builder objects/callbacks.
# Output: Developer::Dashboard::RuntimeManager object.
sub new {
my ( $class, %args ) = @_;
my $config = $args{config} || die 'Missing config';
my $files = $args{files} || die 'Missing file registry';
my $paths = $args{paths} || die 'Missing path registry';
my $runner = $args{runner} || die 'Missing collector runner';
my $app_builder = $args{app_builder} || die 'Missing app builder';
return bless {
app_builder => $app_builder,
collectors => $args{collectors} || Developer::Dashboard::Collector->new( paths => $paths ),
config => $config,
files => $files,
paths => $paths,
runner => $runner,
}, $class;
}
# start_web(%args)
# Starts the dashboard web service in foreground or background mode.
# Input: host, port, worker count, ssl flag, and foreground options.
# Output: server return value in foreground mode or child pid in background mode.
sub start_web {
my ( $self, %args ) = @_;
my $host = '0.0.0.0';
if ( defined $args{host} ) {
$host = $args{host};
}
my $port = 7890;
if ( defined $args{port} ) {
$port = $args{port};
}
my $workers = 1;
if ( defined $args{workers} ) {
$workers = $args{workers};
}
my $ssl = $args{ssl} ? 1 : 0;
die 'Worker count must be a positive integer' if $workers !~ /^\d+$/ || $workers < 1;
my $foreground = $args{foreground} ? 1 : 0;
if ($foreground) {
$self->_close_inherited_fds( preserve_harness => 1 );
my $server = $self->{app_builder}->( host => $host, port => $port, workers => $workers, ssl => $ssl );
return $server->run;
}
my $running = $self->running_web;
return $running->{pid}
if $running
&& $running->{host} eq $host
&& $running->{port} == $port
&& ( ( $running->{workers} || 1 ) == $workers )
&& ( ( $running->{ssl} || 0 ) == $ssl );
if (is_windows()) {
return $self->_start_web_windows_background(
host => $host,
port => $port,
workers => $workers,
( run in 1.624 second using v1.01-cache-2.11-cpan-140bd7fdf52 )