Clio

 view release on metacpan or  search on metacpan

lib/Clio.pm  view on Meta::CPAN


sub _build_process_manager {
    my $self = shift;

    my $proc_mngr = Clio::ProcessManager->new(
        c => $self,
    );

    return $proc_mngr;
}

sub _build_server {
    my $self = shift;

    my $server_class = $self->config->server_class;

    return $server_class->new(
        c => $self,
    );
}

sub BUILD {
    my $self = shift;

    $self->config->process;
};



sub run {
    my $self = shift;

    $self->_daemonize();

    $self->process_manager->start;

    $self->server->start;
};


sub log {
    my $self = shift;
    my $caller = shift || caller();

    $self->_logger->logger($caller);
}

sub _daemonize {
    my $self = shift;

    my $log_method;

    my ($user, $group) = @{ $self->config->run_as_user_group };

    return unless defined $user && defined $group;

    # set user
    my $uid = $user =~ /\A\d+\z/ ? $user : getpwnam($user);

    # set group
    my $gid = $group =~ /\A\d+\z/ ? $group : getgrnam($group);

    daemonize( $uid, $gid, $self->config->pid_file );
}


1;

__END__
=pod

=encoding utf-8

=head1 NAME

Clio - Command Line Input/Output with sockets and HTTP

=head1 VERSION

version 0.02

=head1 DESCRIPTION

Clio will allow you to connect to your command line utilities over network
socket and HTTP.

Please see L<clio> for configuration options and usage.

=head1 ATTRIBUTES

=head2 config_file

Path to Clio config file.

Required.

=head2 config

L<Clio::Config> object.

=head2 process_manager

L<Clio::ProcessManager> object.

=head2 server

Server object of class specified in configuration.

=head1 METHODS

=head2 run

Daemonizes if required by configuration.

Starts L<"process_mananager"> and L<"server">.

=head2 log

    my $logger = $c->log( $caller);

Returns logger object of class specified by configuration.

=head1 INSTALLATION



( run in 1.556 second using v1.01-cache-2.11-cpan-5735350b133 )