1 package Reaction::UI::ViewPort::Collection;
4 use Scalar::Util qw/blessed/;
5 use aliased 'Reaction::InterfaceModel::Collection' => 'IM_Collection';
6 use aliased 'Reaction::UI::ViewPort::Object';
8 class Collection is 'Reaction::UI::ViewPort', which {
10 has members => (is => 'rw', isa => 'ArrayRef', lazy_build => 1);
12 has collection => (is => 'ro', isa => IM_Collection, required => 1);
13 has current_collection => (is => 'rw', isa => IM_Collection, lazy_build => 1);
15 has member_args => ( is => 'rw', isa => 'HashRef', lazy_build => 1);
16 has member_class => ( is => 'ro', isa => 'Str', lazy_build => 1);
18 implements BUILD => as {
19 my ($self, $args) = @_;
20 if( my $member_args = delete $args->{Member} ){
21 $self->member_args( $member_args );
25 implements _build_member_args => as{ {} };
27 implements _build_member_class => as{ Object };
29 after clear_current_collection => sub{
30 shift->clear_members; #clear the members the current collection changes, duh
33 implements _build_current_collection => as {
34 return $_[0]->collection;
37 #I'm not really sure why this is here all of a sudden.
38 implements model => as { shift->current_collection };
40 implements _build_members => as {
43 my $args = $self->member_args;
46 my $loc = join('-', $self->location, 'member');
47 my $class = $self->member_class;
49 #replace $i with a real unique identifier so that we don't run a risk of
50 # events being passed down to the wrong viewport. for now i disabled event
51 # passing until i fix this (groditi)
52 for my $obj ( $self->current_collection->members ) {
53 my $type = blessed $obj;
54 my $builder_cache = $builders->{$type} ||= {};
55 my $member = $class->new(
58 location => join('-', $loc, $i++),
59 builder_cache => $builder_cache,
62 push(@members, $member);
75 Reaction::UI::ViewPort::Collection
79 Creates, from an InterfaceModel::Collection, a list of viewports representing each
80 member of the collection.
86 =head2 current_collection
94 =head1 INTERNAL METHODS
96 These methods, although stable, are subject to change without notice. These are meant
97 to be used only by developers. End users should refrain from using these methods to
98 avoid potential breakages.
102 =head2 get_builder_for
108 See L<Reaction::Class> for authors.
112 See L<Reaction::Class> for the license.