added meta_info for VP::SiteLayout
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Collection.pm
CommitLineData
ddccc6a2 1package Reaction::UI::ViewPort::Collection;
2
3use Reaction::Class;
4use Scalar::Util qw/blessed/;
5use aliased 'Reaction::InterfaceModel::Collection' => 'IM_Collection';
6use aliased 'Reaction::UI::ViewPort::Object';
7
8class Collection is 'Reaction::UI::ViewPort', which {
9
10 has members => (is => 'rw', isa => 'ArrayRef', lazy_build => 1);
11
12 has collection => (is => 'ro', isa => IM_Collection, required => 1);
13 has current_collection => (is => 'rw', isa => IM_Collection, lazy_build => 1);
14
15 has member_args => ( is => 'rw', isa => 'HashRef', lazy_build => 1);
16 has member_class => ( is => 'ro', isa => 'Str', lazy_build => 1);
17
18 implements BUILD => as {
19 my ($self, $args) = @_;
c8fbb8ad 20 my $member_args = delete $args->{Member};
ddccc6a2 21 $self->member_args( $member_args ) if ref $member_args;
22 };
23
c8fbb8ad 24 implements _build_member_args => as{ {} };
25
ddccc6a2 26 implements _build_member_class => as{ Object };
27
28 after clear_current_collection => sub{
c8fbb8ad 29 shift->clear_members; #clear the members the current collection changes, duh
ddccc6a2 30 };
31
32 implements _build_current_collection => as {
33 shift->collection;
34 };
35
c8fbb8ad 36 #I'm not really sure why this is here all of a sudden.
37 implements model => as { shift->current_collection };
ddccc6a2 38
39 implements _build_members => as {
40 my ($self) = @_;
41 my (@members, $i);
42 my $args = $self->member_args;
43 my $builders = {};
44 my $ctx = $self->ctx;
45 my $loc = join('-', $self->location, 'member');
46 my $class = $self->member_class;
47
48 #replace $i with a real unique identifier so that we don't run a risk of
49 # events being passed down to the wrong viewport. for now i disabled event
50 # passing until i fix this (groditi)
51 for my $obj ( $self->current_collection->members ) {
52 my $type = blessed $obj;
53 my $builder_cache = $builders->{$type} ||= {};
54 my $member = $class->new(
55 ctx => $ctx,
c8fbb8ad 56 model => $obj,
ddccc6a2 57 location => join('-', $loc, $i++),
58 builder_cache => $builder_cache,
59 %$args
60 );
61 push(@members, $member);
62 }
63 return \@members;
64 };
65
66};
67
2dba7201 681;
ddccc6a2 69
2dba7201 70__END__;
ddccc6a2 71
2dba7201 72=head1 NAME
73
74Reaction::UI::ViewPort::Collection
75
76=head1 DESCRIPTION
77
78Creates, from an InterfaceModel::Collection, a list of viewports representing each
79member of the collection.
80
81=head1 ATTRIBUTES
82
83=head2 collection
84
85=head2 current_collection
86
87=head2 member_args
88
89=head2 member_class
90
91=head1
92
93=head1 INTERNAL METHODS
94
95These methods, although stable, are subject to change without notice. These are meant
96to be used only by developers. End users should refrain from using these methods to
97avoid potential breakages.
98
99=head2 BUILD
100
101=head2 get_builder_for
102
103=head2 model
104
105=head1 AUTHORS
106
107See L<Reaction::Class> for authors.
108
109=head1 LICENSE
110
111See L<Reaction::Class> for the license.
112
113=cut