1 package App::Clifton::Component;
3 # define this up here to avoid uninitialised warnings
5 my ($self, $args) = @_;
6 "${self}: ".join ', ', map "$_ => ".$args->{$_}, keys %$args;
9 use Log::Contextual qw(:log);
12 extends 'Moo::Object', 'IO::Async::Notifier';
14 # we're replacing Notifier's constructor so need to set up its default
15 has children => (is => 'bare', default => sub { [] });
18 my ($self, $args) = @_;
20 "Constructing "._debug_self($self, $args);
22 if (my $parent = $args->{parent_component}) {
23 $parent->add_child($self);
28 my ($self, $class, $args) = @_;
29 if ($class->isa('App::Clifton::Component')) {
30 $class->new(%{$args||{}}, parent_component => $self);
32 my $new = $class->new(%{$args||{}});
33 $self->add_child($new);
38 around _replace_weakself => sub {
39 my ($orig, $self) = (shift, shift);
40 $self->_eval_cb($self->$orig(@_));
43 around _capture_weakself => sub {
44 my ($orig, $self) = (shift, shift);
45 $self->_eval_cb($self->$orig(@_));
49 my ($self, $code) = @_;
50 $self->get_loop->later($self->_eval_cb($code));
54 my ($self, $code) = @_;
58 eval { $code->(@_); 1 }
59 or log_error { "Exception from ${self}: $@" };
65 log_debug { "Destroying "._debug_self($self, $self) };