1 package Reaction::UI::Widget::Container;
3 use Reaction::UI::WidgetClass;
5 use aliased 'Reaction::UI::ViewPort';
7 use namespace::clean -except => [ qw(meta) ];
12 # somewhat evil. fragment returns ($name, $code) to pass to implements
13 # or a method modifier name, so [1] will get us just the code
15 # This is convenient to do here but DO NOT duplicate this code outside of
16 # the same dist as WidgetClass since it's internals-dependent.
18 my $child_fragment_method
19 = (fragment container_child {
20 arg '_' => $_{viewport}->$child_name;
24 around _method_for_fragment_name => sub {
27 my ($fragment_name) = @_;
28 if (defined($child_name)
29 && $fragment_name eq $child_name) {
30 return $self->$orig(@_) || $child_fragment_method;
32 return $self->$orig(@_);
35 before _fragment_widget => sub {
36 my ($self, $do_render, $args, $new_args) = @_;
37 my @contained_names = $self->_contained_names($args->{viewport});
38 foreach my $name (@contained_names) {
39 $new_args->{$name} ||= sub {
40 local $child_name = $name;
41 $self->render($name, @_);
46 implements _contained_names => sub {
49 foreach my $attr ($vp->meta->get_all_attributes) {
50 next unless eval { $attr->type_constraint->name->isa(ViewPort) };
51 my $name = $attr->name;
52 next if ($name eq 'outer');
58 __PACKAGE__->meta->make_immutable;
66 Reaction::UI::Widget::Container - Provide viewport attibutes in the current viewport
70 This widget base class (with no corresponding layout set) will search the viewports
71 attributes for those that contain L<Reaction::UI::ViewPort> classes or subclasses.
73 These attributes will then be provided as arguments to the C<widget> fragment and
74 can be rendered by their attribute name.
80 Provides rendering callbacks to those attributes of the viewport that can contain
81 viewport objects as arguments to the C<widget> layout.
85 See L<Reaction::Class> for authors.
89 See L<Reaction::Class> for the license.