aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/UI/Widget/Container.pm
diff options
context:
space:
mode:
authormatthewt <matthewt@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2008-01-29 11:35:18 +0000
committermatthewt <matthewt@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2008-01-29 11:35:18 +0000
commit1c41e332e495bee30ba8c31d44023fddb7e2602b (patch)
tree294fa23183b6a317ec8ef3a7100514680ebd4d36 /lib/Reaction/UI/Widget/Container.pm
parent5976ddc40b95fb45edc007e8bb67d0db58d3bb2e (diff)
downloadreaction-1c41e332e495bee30ba8c31d44023fddb7e2602b.tar.gz
reaction-1c41e332e495bee30ba8c31d44023fddb7e2602b.zip
container widget
Diffstat (limited to 'lib/Reaction/UI/Widget/Container.pm')
-rw-r--r--lib/Reaction/UI/Widget/Container.pm59
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/Reaction/UI/Widget/Container.pm b/lib/Reaction/UI/Widget/Container.pm
new file mode 100644
index 0000000..3b11afb
--- /dev/null
+++ b/lib/Reaction/UI/Widget/Container.pm
@@ -0,0 +1,59 @@
+package Reaction::UI::Widget::Container;
+
+use Reaction::UI::WidgetClass;
+
+use aliased 'Reaction::UI::ViewPort';
+
+class Container which {
+
+ our $child_name;
+
+ # somewhat evil. fragment returns ($name, $code) to pass to implements
+ # or a method modifier name, so [1] will get us just the code
+
+ # This is convenient to do here but DO NOT duplicate this code outside of
+ # the same dist as WidgetClass since it's internals-dependent.
+
+ my $child_fragment_method
+ = (fragment container_child {
+ arg '_' => $_{viewport}->$child_name;
+ render 'viewport';
+ })[1];
+
+ around _method_for_fragment_name => sub {
+ my $orig = shift;
+ my $self = shift;
+ my ($fragment_name) = @_;
+ if (defined($child_name)
+ && $fragment_name eq $child_name) {
+ return $self->$orig(@_) || $child_fragment_method;
+ }
+ return $self->$orig(@_);
+ };
+
+ before _fragment_widget => sub {
+ my ($self, $do_render, $args, $new_args) = @_;
+ my @contained_names = $self->_contained_names($args->{viewport});
+ foreach my $name (@contained_names) {
+ $new_args->{$name} ||= sub {
+ local $child_name = $name;
+ $self->render($name, @_);
+ };
+ }
+ };
+
+ implements _contained_names => sub {
+ my ($self, $vp) = @_;
+ my @names;
+ foreach my $attr ($vp->meta->compute_all_applicable_attributes) {
+ next unless eval { $attr->type_constraint->name->isa(ViewPort) };
+ my $name = $attr->name;
+ next if ($name eq 'outer');
+ push(@names, $name);
+ }
+ return @names;
+ };
+
+};
+
+1;