diff options
author | groditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2007-12-17 16:32:16 +0000 |
---|---|---|
committer | groditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2007-12-17 16:32:16 +0000 |
commit | ddccc6a29affc90888a59f14d698fd3afb2757dc (patch) | |
tree | f6dec89af81aeb84fb308c961d92d049a7147e93 /lib/Reaction/UI/ViewPort/Collection.pm | |
parent | 27959b780ce142e88419e66dc8e6e7d571a41bb3 (diff) | |
download | reaction-ddccc6a29affc90888a59f14d698fd3afb2757dc.tar.gz reaction-ddccc6a29affc90888a59f14d698fd3afb2757dc.zip |
new renamed viewports
Diffstat (limited to 'lib/Reaction/UI/ViewPort/Collection.pm')
-rw-r--r-- | lib/Reaction/UI/ViewPort/Collection.pm | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/lib/Reaction/UI/ViewPort/Collection.pm b/lib/Reaction/UI/ViewPort/Collection.pm new file mode 100644 index 0000000..c728f8e --- /dev/null +++ b/lib/Reaction/UI/ViewPort/Collection.pm @@ -0,0 +1,67 @@ +package Reaction::UI::ViewPort::Collection; + +use Reaction::Class; +use Scalar::Util qw/blessed/; +use aliased 'Reaction::InterfaceModel::Collection' => 'IM_Collection'; +use aliased 'Reaction::UI::ViewPort::Object'; + +class Collection is 'Reaction::UI::ViewPort', which { + + has members => (is => 'rw', isa => 'ArrayRef', lazy_build => 1); + + has collection => (is => 'ro', isa => IM_Collection, required => 1); + has current_collection => (is => 'rw', isa => IM_Collection, lazy_build => 1); + + has member_args => ( is => 'rw', isa => 'HashRef', lazy_build => 1); + has member_class => ( is => 'ro', isa => 'Str', lazy_build => 1); + + implements BUILD => as { + my ($self, $args) = @_; + my $entity_args = delete $args->{Member}; + $self->member_args( $member_args ) if ref $member_args; + }; + + implements _build_member_class => as{ Object }; + + after clear_current_collection => sub{ + shift->clear_entities; #clear the entitiesis the current collection changes, duh + }; + + implements _build_current_collection => as { + shift->collection; + }; + + implements model + + implements _build_members => as { + my ($self) = @_; + my (@members, $i); + my $args = $self->member_args; + my $builders = {}; + my $ctx = $self->ctx; + my $loc = join('-', $self->location, 'member'); + my $class = $self->member_class; + + #replace $i with a real unique identifier so that we don't run a risk of + # events being passed down to the wrong viewport. for now i disabled event + # passing until i fix this (groditi) + for my $obj ( $self->current_collection->members ) { + my $type = blessed $obj; + my $builder_cache = $builders->{$type} ||= {}; + my $member = $class->new( + ctx => $ctx, + object => $obj, + location => join('-', $loc, $i++), + builder_cache => $builder_cache, + %$args + ); + push(@members, $member); + } + return \@members; + }; + +}; + + + +1; |