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)
);
sub _spec_to_constructor_args {
my ($self, $spec) = @_;
+{
+ name => $spec->{name},
jabber => BridgeConfig_Jabber->new($spec->{jabber}),
irc => BridgeConfig_IRC->new($spec->{irc}),
}
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}: $_" } }
};
}
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);
}
}
};
my $deps = {};
+ $args ||= {};
if (my $dep_call = $self->can("_dependencies_for_${do}")) {
$deps = $self->$dep_call($args);
}
$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)) {
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 {
my $conf = $self->jabber_config;
$xmpp->login(
jid => $conf->user, host => $conf->server, password => $conf->pass,
- on_message => $self->_replace_weakself('handle_message'),
);
$xmpp;
}