r18493@agaton (orig r702): wreis | 2008-05-02 22:28:12 +0100
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort.pm
index 7d24efc..02a1390 100644 (file)
@@ -5,8 +5,11 @@ use Scalar::Util qw/blessed/;
 
 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 => (
@@ -15,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 {
     '';
@@ -87,10 +90,21 @@ 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}) {
-        #my $name = eval{$self->name};
-        #$self->ctx->log->debug("Applying Event: $event on $name with value: ". $events->{$event});
+        if (DEBUG_EVENTS) {
+          my $name = join(' at ', $self, $self->location);
+          $self->ctx->log->debug(
+            "Applying Event: $event on $name with value: "
+            .(defined $events->{$event} ? $events->{$event} : '<undef>')
+          );
+        }
         $self->$event($events->{$event});
       }
     }
@@ -98,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);