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