… | |
… | |
10 | # |
10 | # |
11 | # and expects the following exti message types |
11 | # and expects the following exti message types |
12 | # w_r rid res # widget call return |
12 | # w_r rid res # widget call return |
13 | # w_e id name args # widget_event |
13 | # w_e id name args # widget_event |
14 | |
14 | |
|
|
15 | our $DEBUG = 1; |
|
|
16 | |
15 | cf::client->attach ( |
17 | cf::client->attach ( |
16 | on_connect => sub { |
18 | on_connect => sub { |
17 | my ($ns) = @_; |
19 | my ($ns) = @_; |
18 | |
20 | |
19 | Scalar::Util::weaken (my $weakns = $ns); |
21 | Scalar::Util::weaken (my $weakns = $ns); |
… | |
… | |
155 | sub msg { |
157 | sub msg { |
156 | my ($self, $type, %msg) = @_; |
158 | my ($self, $type, %msg) = @_; |
157 | |
159 | |
158 | if (my $ns = shift->{ns}) { |
160 | if (my $ns = shift->{ns}) { |
159 | $msg{msgtype} = $type; |
161 | $msg{msgtype} = $type; |
|
|
162 | warn "msg " . $ns->{json_coder}->encode (\%msg) if $DEBUG;#d# |
160 | $ns->send_packet ("ext " . $ns->{json_coder}->encode (\%msg)); |
163 | $ns->send_packet ("ext " . $ns->{json_coder}->encode (\%msg)); |
161 | } |
164 | } |
162 | } |
165 | } |
163 | |
166 | |
164 | sub new { |
167 | sub new { |
165 | my ($self, $class, %args) = @_; |
168 | my ($self, $class, %args) = @_; |
166 | |
169 | |
167 | my $id = ++$self->{ns}{id}; |
170 | my $id = ++$self->{ns}{id}; |
168 | |
171 | |
169 | my $proxy = $self->{_w}{$id} = bless { |
172 | my $proxy = bless { |
170 | id => $id, |
173 | id => $id, |
171 | }, "ext::widget::proxy"; |
174 | }, "ext::widget::proxy"; |
172 | |
175 | |
|
|
176 | Scalar::Util::weaken ($self->{_w}{$id} = $proxy); |
173 | Scalar::Util::weaken ($proxy->{ws} = $self); |
177 | Scalar::Util::weaken ($proxy->{ws} = $self); |
174 | Scalar::Util::weaken ($proxy->{ns} = $self->{ns}); |
178 | Scalar::Util::weaken ($proxy->{ns} = $self->{ns}); |
175 | Scalar::Util::weaken ($self->{ns}{widget}{$id} = $proxy); |
179 | Scalar::Util::weaken ($self->{ns}{widget}{$id} = $proxy); |
176 | |
180 | |
177 | for my $ev (grep /^on_/, keys %args) { |
181 | for my $ev (grep /^on_/, keys %args) { |
… | |
… | |
196 | sub DESTROY { |
200 | sub DESTROY { |
197 | my ($self) = @_; |
201 | my ($self) = @_; |
198 | |
202 | |
199 | delete $self->{ns}{widget}{$self->{id}}; |
203 | delete $self->{ns}{widget}{$self->{id}}; |
200 | |
204 | |
201 | #warn "DES<$self> $self->{ws}\n";#d# |
|
|
202 | if (my $ws = $self->{ws}) { |
205 | if (my $ws = $self->{ws}) { |
203 | $self->msg (w_c => name => "destroy"); |
206 | $self->msg (w_c => name => "destroy"); |
204 | delete $ws->{_w}{$self->{id}}; |
207 | delete $ws->{_w}{$self->{id}}; |
205 | } |
208 | } |
206 | } |
209 | } |