actually load config
[scpubgit/Clifton.git] / lib / App / Clifton / Server.pm
1 package App::Clifton::Server;
2
3 use aliased 'App::Clifton::ServiceContainer';
4 use aliased 'App::Clifton::ConfigLoader';
5 use Moo;
6
7 extends 'App::Clifton::Service';
8
9 sub BUILD {
10   my ($self, $args) = @_;
11   $args->{loop}->add($self);
12   $self->$_ for qw(services);
13 }
14
15 has config_file => (is => 'ro', required => 1);
16
17 has config_loader => (is => 'lazy');
18
19 has current_config => (is => 'rw');
20
21 sub _build_config_loader { ConfigLoader->new }
22
23 has services => (is => 'lazy');
24
25 sub _build_services {
26   shift->_new_child(ServiceContainer, {});
27 }
28
29 sub reload_config { shift->_do(reload_config => @_) }
30 sub shutdown { shift->_do(shutdown => @_) }
31
32 sub _body_for_reload_config {
33   my ($self, $args) = @_;
34   my $config = $self->config_loader->config_from_file($self->config_file);
35   $self->current_config($config);
36   $args->{on_finished}->($config);
37 }
38
39 1;