Skip to content

Commit

Permalink
Propagage rules, add base Module
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Mar 1, 2010
1 parent e046993 commit 47c5574
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lib/Soric3/Kernel.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Soric3::Kernel {
is => 'bare',
default => sub { {} },
handles => { loaded_modules => 'keys',
modules => 'values',
module_loaded => 'exists',
_bind_module => 'set',
module => 'get',
Expand All @@ -26,7 +27,7 @@ class Soric3::Kernel {
# munging of client classes? I like this
);

# Do a preorder traversal of the module dependancy tree, instantiating and
# Do a postorder traversal of the module dependancy tree, instantiating and
# binding all new modules, and removing unused ones.
method _load_module(HashRef $used, Str $name where { $_ =~ /^[a-z]+$/ }) {
return if $used->{$name};
Expand Down
28 changes: 28 additions & 0 deletions lib/Soric3/Module.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use MooseX::Declare;

class Soric3::Module {
# XXX do the schema here

has kernel => (
isa => 'Soric3::Kernel',
is => 'ro',
required => 1,
weak_ref => 1,
);

method requires($class:) {
}

method broadcast(RoleName $obsrole, Str $method, @args) {
return if !$self->kernel;
for my $receiver ($self->kernel->modules) {
next if !$receiver->does($obsrole);
$receiver->$method(@args);
}
}

method log(Str $prio, Str $text) {
# TODO proper logging
warn ref($self) . " - [$prio] $text\n";
}
}
22 changes: 15 additions & 7 deletions lib/Soric3/Module/Irc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class Soric3::Module::Irc extends Soric3::Module
enum_irc_connections => 'keys' },
);

method on_new_sends(Str $conn_name) {
method on_sends_changed(Str $conn_name) {
if ((my $conn = $self->_connection($conn_name)) {
$conn->new_sends;
$conn->sends_changed;
}
}

Expand All @@ -36,7 +36,8 @@ class Soric3::Module::Irc extends Soric3::Module
{ nick => $nick, user => $user, real => $real,
password => $password });

$self->broadcast('ConnectionObserver', 'connection_created', $tag);
$self->broadcast('ConnectionObserver', 'connection_status_changed',
$tag);
}

method delete_connection(Str $tag, Str $reason) {
Expand All @@ -46,7 +47,8 @@ class Soric3::Module::Irc extends Soric3::Module
$conn->disconnect($reason);

$self->_unbind_connection($tag);
$self->broadcast('ConnectionObserver', 'connection_deleted', $tag);
$self->broadcast('ConnectionObserver', 'connection_status_changed',
$tag);
}
}

Expand Down Expand Up @@ -79,17 +81,23 @@ class Soric3::Module::Irc::Connection
is => 'rw',
);

has error => (
isa => 'Any',
predicate => 'failed',
is => 'rw',
);

method BUILD() {
$self->reg_cb(
registered => sub { shift->alert },
connect => sub {
my ($self, $err) = @_;
return unless defined $err;
$self->failed($err);
$self->error($err);

$self->broadcast(
'ConnectionObserver', 'connection_state_changed',
$self->tag, 'failed', $err) if $self->backref;
'ConnectionObserver', 'connection_status_changed',
$self->tag) if $self->backref;
},
before_irc_ping => sub {
my ($self, $msg) = @_;
Expand Down

0 comments on commit 47c5574

Please sign in to comment.