r18493@agaton (orig r702): wreis | 2008-05-02 22:28:12 +0100
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort.pm
index 5a18f50..02a1390 100644 (file)
@@ -3,12 +3,13 @@ package Reaction::UI::ViewPort;
 use Reaction::Class;
 use Scalar::Util qw/blessed/;
 
-sub DEBUG_EVENTS () { $ENV{REACTION_UI_VIEWPORT_DEBUG_EVENTS} }
-
 class ViewPort which {
 
+  sub DEBUG_EVENTS () { $ENV{REACTION_UI_VIEWPORT_DEBUG_EVENTS} }
+
   has location => (isa => 'Str', is => 'rw', required => 1);
   has layout => (isa => 'Str', is => 'rw', lazy_build => 1);
+  has layout_args => (isa => 'HashRef', is => 'ro', default => sub { {} });
   has outer => (isa => 'Reaction::UI::ViewPort', is => 'rw', weak_ref => 1);
   has inner => (isa => 'Reaction::UI::ViewPort', is => 'rw');
   has focus_stack => (
@@ -17,7 +18,7 @@ class ViewPort which {
   has _tangent_stacks => (
     isa => 'HashRef', is => 'ro', default => sub { {} }
   );
-  has ctx => (isa => 'Catalyst', is => 'ro', required => 1);
+  has ctx => (isa => 'Catalyst', is => 'ro'); #, required => 1);
 
   implements _build_layout => as {
     '';
@@ -89,13 +90,19 @@ class ViewPort which {
 
   implements handle_events => as {
     my ($self, $events) = @_;
+    my $exists = exists $events->{exists};
+    if ($exists) {
+      my %force = $self->force_events;
+      my @need = grep { !exists $events->{$_} } keys %force;
+      @{$events}{@need} = @force{@need};
+    }
     foreach my $event ($self->accept_events) {
       if (exists $events->{$event}) {
         if (DEBUG_EVENTS) {
           my $name = join(' at ', $self, $self->location);
           $self->ctx->log->debug(
             "Applying Event: $event on $name with value: "
-            .$events->{$event}
+            .(defined $events->{$event} ? $events->{$event} : '<undef>')
           );
         }
         $self->$event($events->{$event});
@@ -105,6 +112,8 @@ class ViewPort which {
 
   implements accept_events => as { () };
 
+  implements force_events => as { () };
+
   implements event_id_for => as {
     my ($self, $name) = @_;
     return join(':', $self->location, $name);