Commit | Line | Data |
37efeb68 |
1 | #This is an experimental method for working with |
2 | #Log::Contextual crossing Object::Remote connections |
3 | #transparently |
4 | |
f7ea4120 |
5 | package Object::Remote::Role::LogForwarder; |
6 | |
7 | use Moo::Role; |
4a9fa1a5 |
8 | use Scalar::Util qw(weaken); |
9 | use Carp qw(cluck); |
f7ea4120 |
10 | |
11 | with 'Log::Contextual::Role::Router'; |
12 | |
13 | #TODO re-weaken router references when object::remote |
14 | #weak reference operation is figured out |
15 | |
4a9fa1a5 |
16 | has child_routers => ( is => 'ro', required => 1, default => sub { [] } ); |
f7ea4120 |
17 | has parent_router => ( is => 'rw', );#weak_ref => 1 ); |
18 | |
4a9fa1a5 |
19 | sub BUILD { } |
20 | |
21 | after BUILD => sub { |
5d59cb98 |
22 | my ($self) = @_; |
23 | # my $parent = $self->parent_router; |
24 | # return unless defined $parent ; |
25 | # $parent->add_child_router($self); |
4a9fa1a5 |
26 | }; |
27 | |
28 | sub describe { |
5d59cb98 |
29 | my ($self, $depth) = @_; |
30 | $depth = -1 unless defined $depth; |
31 | $depth++; |
32 | my $buf = "\t" x $depth . $self->description . "\n"; |
33 | foreach my $child (@{$self->child_routers}) { |
34 | next unless defined $child; |
35 | $buf .= $child->describe($depth); |
36 | } |
4a9fa1a5 |
37 | |
5d59cb98 |
38 | return $buf; |
4a9fa1a5 |
39 | } |
40 | |
f7ea4120 |
41 | sub add_child_router { |
5d59cb98 |
42 | my ($self, $router) = @_; |
43 | push(@{ $self->child_routers }, $router); |
37efeb68 |
44 | #TODO re-weaken when object::remote proxied |
45 | #weak references is figured out |
4a9fa1a5 |
46 | # weaken(${ $self->child_routers }[-1]); |
5d59cb98 |
47 | return; |
f7ea4120 |
48 | } |
49 | |
4a9fa1a5 |
50 | #sub remove_child_router { |
51 | # my ($self, $description) = @_; |
52 | # return delete $self->child_routers->{$description}; |
53 | #} |
f7ea4120 |
54 | |
55 | after handle_log_message => sub { |
5d59cb98 |
56 | my ($self, @args) = @_; |
57 | my $parent = $self->parent_router; |
f7ea4120 |
58 | |
5d59cb98 |
59 | return unless defined $parent; |
60 | $parent->handle_log_message(@args); |
f7ea4120 |
61 | }; |
62 | |
63 | 1; |
5d59cb98 |
64 | |