| 1 | package POE::XUL::EventManager; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use Scalar::Util qw(weaken); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 0 | ▶ | use XUL::Node::Event; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 8 | |||
| 9 | sub new { | ||
| 10 | my $class = shift; | ||
| 11 | bless { nodes => {} }, $class | ||
| 12 | } | ||
| 13 | |||
| 14 | sub make_event { | ||
| 15 | my ($self, $request) = @_; | ||
| 16 | my $id = $request->{source}; | ||
| 17 | croak "cannot make event with no source" unless $id; | ||
| 18 | $request->{source} = $self->get_node($id); | ||
| 19 | croak "node with id [$id] not found" unless $request->{source}; | ||
| 20 | return XUL::Node::Event->make_event($request); | ||
| 21 | } | ||
| 22 | |||
| 23 | sub fire_event { | ||
| 24 | my ($self, $event) = (shift,shift); | ||
| 25 | $event->source->fire_event($event,@_); | ||
| 26 | } | ||
| 27 | |||
| 28 | sub register_node { | ||
| 29 | my ($self, $id, $node) = @_; | ||
| 30 | my $nodes = $self->{nodes}; | ||
| 31 | $nodes->{$id} = $node; | ||
| 32 | weaken $nodes->{$id}; | ||
| 33 | } | ||
| 34 | |||
| 35 | # TODO: cleanup dangling weak ref now and then | ||
| 36 | sub get_node { shift->{nodes}->{pop()} } | ||
| 37 | |||
| 38 | 1; | ||
| 39 | |||