From: Matt S Trout Date: Wed, 16 Feb 2011 11:34:48 +0000 (+0000) Subject: join the dots so server starts on reload_config X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=38180dc82ce612829b2c52d661e515fe60ac0f1d;p=scpubgit%2FClifton.git join the dots so server starts on reload_config --- diff --git a/lib/App/Clifton/BridgeConfig.pm b/lib/App/Clifton/BridgeConfig.pm index abe0727..baa97ff 100644 --- a/lib/App/Clifton/BridgeConfig.pm +++ b/lib/App/Clifton/BridgeConfig.pm @@ -5,6 +5,8 @@ use aliased 'App::Clifton::BridgeConfig::Jabber' => 'BridgeConfig_Jabber'; use aliased 'App::Clifton::BridgeConfig::IRC' => 'BridgeConfig_IRC'; use Moo; +has name => (is => 'ro', required => 1); + has jabber => ( is => 'ro', required => 1, isa => object_of_class(BridgeConfig_Jabber) ); diff --git a/lib/App/Clifton/BridgeConfigSet.pm b/lib/App/Clifton/BridgeConfigSet.pm index a6c8e51..eb35f77 100644 --- a/lib/App/Clifton/BridgeConfigSet.pm +++ b/lib/App/Clifton/BridgeConfigSet.pm @@ -13,6 +13,7 @@ sub _set_over { 'name' } sub _spec_to_constructor_args { my ($self, $spec) = @_; +{ + name => $spec->{name}, jabber => BridgeConfig_Jabber->new($spec->{jabber}), irc => BridgeConfig_IRC->new($spec->{irc}), } diff --git a/lib/App/Clifton/Component.pm b/lib/App/Clifton/Component.pm index 6f857ba..5604bae 100644 --- a/lib/App/Clifton/Component.pm +++ b/lib/App/Clifton/Component.pm @@ -55,7 +55,8 @@ sub _eval_cb { my ($self, $code) = @_; my $str = "$self"; sub { - try { $code->(@_) } catch { log_error { "Exception from ${self}: $_" } } + my @args = @_; + try { $code->(@args) } catch { log_error { "Exception from ${self}: $_" } } }; } diff --git a/lib/App/Clifton/Server.pm b/lib/App/Clifton/Server.pm index 4a46499..07a10bb 100644 --- a/lib/App/Clifton/Server.pm +++ b/lib/App/Clifton/Server.pm @@ -39,6 +39,21 @@ sub shutdown { shift->_do(shutdown => @_) } sub _body_for_reload_config { my ($self, $args) = @_; my $config = $self->config_loader->config_from_file($self->config_file); + my $jt = $self->jabber_towers; + foreach my $bridge ($config->bridges->flatten) { + + $jt->{$bridge->name} = $self->_new_child( + Jabber_Tower, { + jabber_config => $bridge->jabber, + irc_config => $bridge->irc, + bridge_name => $bridge->name, + server => $self, + } + ); + } + foreach my $user ($config->users->flatten) { + $jt->{$_}->userconfig_set->add($user) for @{$user->allow}; + } $self->current_config($config); $args->{on_finished}->($config); } diff --git a/lib/App/Clifton/Service.pm b/lib/App/Clifton/Service.pm index 49bb786..b754183 100644 --- a/lib/App/Clifton/Service.pm +++ b/lib/App/Clifton/Service.pm @@ -20,6 +20,7 @@ sub _do { } }; my $deps = {}; + $args ||= {}; if (my $dep_call = $self->can("_dependencies_for_${do}")) { $deps = $self->$dep_call($args); } diff --git a/lib/App/Clifton/Set.pm b/lib/App/Clifton/Set.pm index d938189..2bbf860 100644 --- a/lib/App/Clifton/Set.pm +++ b/lib/App/Clifton/Set.pm @@ -18,6 +18,12 @@ sub get { $self->_set->{$self->_spec_to_key($spec)}; } +sub flatten { + my ($self) = @_; + my $set = $self->_set; + map $set->{$_}, sort keys %$set; +} + sub _spec_to_object { my ($self, $spec) = @_; if (blessed($spec) && $spec->isa($self->_set_of_class)) { diff --git a/lib/App/Clifton/Tower/Jabber.pm b/lib/App/Clifton/Tower/Jabber.pm index 44c8d0d..1798f46 100644 --- a/lib/App/Clifton/Tower/Jabber.pm +++ b/lib/App/Clifton/Tower/Jabber.pm @@ -29,7 +29,9 @@ has chain_set => ( sub _build_xmpp_client { my ($self) = @_; - $self->_login_xmpp_client($self->_new_child(XMPP_Client, { })); + $self->_login_xmpp_client($self->_new_child(XMPP_Client, { + on_message => $self->_replace_weakself('handle_message'), + })); } sub _login_xmpp_client { @@ -37,7 +39,6 @@ sub _login_xmpp_client { my $conf = $self->jabber_config; $xmpp->login( jid => $conf->user, host => $conf->server, password => $conf->pass, - on_message => $self->_replace_weakself('handle_message'), ); $xmpp; }