X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FReaction%2FUI%2FViewPort.pm;h=ed9722e02648320664e9bc1a0ea02d6507d119d1;hb=a36b6256ca273526c57e50837f615256b0a1354c;hp=c89e2e95059eca177522b845c9c147ad7cb568fd;hpb=114916fc3b89cfa8e9fbc8d5cc0b0ee54c2a696f;p=catagits%2FReaction.git diff --git a/lib/Reaction/UI/ViewPort.pm b/lib/Reaction/UI/ViewPort.pm index c89e2e9..ed9722e 100644 --- a/lib/Reaction/UI/ViewPort.pm +++ b/lib/Reaction/UI/ViewPort.pm @@ -19,7 +19,7 @@ has focus_stack => ( has _tangent_stacks => ( isa => 'HashRef', is => 'ro', default => sub { {} } ); -has ctx => (isa => 'Catalyst', is => 'ro'); #, required => 1); +has ctx => (isa => 'Catalyst', is => 'ro', weak_ref => 1); #, required => 1); sub _build_layout { ''; @@ -68,25 +68,23 @@ sub apply_child_events { foreach my $child ($self->child_event_sinks) { confess blessed($child) ."($child) is not a valid object" unless blessed($child) && $child->can('apply_events'); - $child->apply_events($events); + my $loc = $child->location; + my %child_events = map { $_ => delete $events->{$_} } + grep { /^${loc}[-:]/ } keys %$events; + $child->apply_events(\%child_events); } } sub apply_our_events { my ($self, $events) = @_; - my @keys = keys %$events; - return unless @keys; my $loc = $self->location; my %our_events; foreach my $key (keys %$events) { if ($key =~ m/^${loc}:(.*)$/) { - $our_events{$1} = $events->{$key}; + $our_events{$1} = delete $events->{$key}; } } - if (keys %our_events) { - #warn "$self: events ".join(', ', %our_events)."\n"; - $self->handle_events(\%our_events); - } + $self->handle_events(\%our_events) if keys %our_events; } sub handle_events { @@ -103,7 +101,7 @@ sub handle_events { my $name = join(' at ', $self, $self->location); print STDERR "Applying Event: $event on $name with value: " - .(defined $events->{$event} ? $events->{$event} : ''); + .(defined $events->{$event} ? $events->{$event} : '')."\n"; } $self->$event($events->{$event}); } @@ -121,14 +119,12 @@ sub event_id_for { sub sort_by_spec { my ($self, $spec, $items) = @_; - return $items if not defined $spec; + return [sort @$items] unless $spec; my @order; if (ref $spec eq 'ARRAY') { @order = @$spec; - } - elsif (not ref $spec) { - return $items unless length $spec; + } elsif (not ref $spec) { @order = split /\s+/, $spec; } @@ -154,7 +150,7 @@ Reaction::UI::ViewPort - Page layout building block # Create a new ViewPort: # $stack isa Reaction::UI::FocusStack object - my $vp = $stack->push_viewport('Reaction::UI::ViewPort', layout => 'xthml'); + my $vp = $stack->push_viewport('Reaction::UI::ViewPort', layout => 'xhtml'); # Fetch ViewPort higher up the stack (further out) my $outer = $vp->outer(); @@ -254,6 +250,16 @@ The layout attribute can either be specifically passed when calling C, or it will be determined using the last part of the ViewPorts classname. +=item layout_args + +This read-only hashref attribute will pass all it's keys as variables to the +layout at render time. They should be accessible from both the layout templates +and the widget, if applicable, through the C<%_> hash. + + $controller->push_viewport(VPName, layout => 'foo', layout_args => { bar => 'bar'}); + $_{bar} #in widget + [% bar %] in template + =item column_order This is generally used by more specialised ViewPorts such as the