sketch out some service code
[scpubgit/Clifton.git] / lib / App / Clifton / Component.pm
1 package App::Clifton::Component;
2
3 # define this up here to avoid uninitialised warnings
4 sub _debug_self {
5   my ($self, $args) = @_;
6   "${self}: ".join ', ', map "$_ => ".$args->{$_}, keys %$args;
7 }
8
9 use Log::Contextual qw(:log);
10 use Moo;
11
12 extends 'IO::Async::Notifier';
13
14 sub BUILD {
15   my ($self, $args) = @_;
16   log_debug {
17     "Constructing "._debug_self($self, $args);
18   };
19   if (my $parent = $args->{parent_component}) {
20     $parent->add_child($self);
21   }
22 }
23
24 sub configure {
25   # If we called the superclass method, any ->new params that were populated
26   # into attributes would cause a croak. While the loss of error checking is
27   # annoying I've got other things to fix right now.
28 }
29
30 sub _new_child {
31   my ($self, $class, $args) = @_;
32   $class->new(%{$args||{}}, parent_component => $self);
33 }
34
35 sub _schedule {
36   my ($self, $code) = @_;
37   $self->get_loop->later($code);
38 }
39
40 sub DESTROY {
41   my ($self) = @_;
42   log_debug { "Destroying "._debug_self($self, $self) };
43 }
44
45 1;