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);
39 my ($self, $code) = @_;
40 $self->get_loop->later($code);
45 log_debug { "Destroying "._debug_self($self, $self) };