1 package Reaction::UI::Controller::Role::GetCollection;
3 use Moose::Role -traits => 'MethodAttributes';
5 has model_name => (isa => 'Str', is => 'rw', required => 1);
6 has collection_name => (isa => 'Str', is => 'rw', required => 1);
10 my $model = $c->model( $self->model_name );
11 confess "Failed to find Catalyst model named: " . $self->model_name
13 my $collection = $self->collection_name;
14 if( my $meth = $model->can( $collection ) ){
16 } elsif ( my $meta = $model->can('meta') ){
17 if ( my $attr = $model->$meta->find_attribute_by_name($collection) ) {
18 my $reader = $attr->get_read_method;
19 return $model->$reader;
22 confess "Failed to find collection $collection";
31 Reaction::UI::Controller::Role::GetCollection
35 Provides a C<get_collection> method, which fetches an C<Collection> object
36 from a specified model.
40 package MyApp::Controller::Foo;
42 use base 'Reaction::Controller';
45 with 'Reaction::UI::Controller::Role::GetCollection';
47 __PACKAGE__->config( model_name => 'MyAppIM', collection_name => 'foos' );
51 my $obj = $self->get_collection($c)->find( $some_key );
58 The name of the model this controller will use as it's data source. Should be a
59 name that can be passed to C<$C-E<gt>model>
61 =head2 collection_name
63 The name of the collection whithin the model that this Controller will be
68 =head2 get_collection $c
70 Returns an instance of the collection this controller uses.
76 =item L<Reaction::UI::Controller>
78 =item L<Reaction::UI::Controller::Role::Action::Simple>
80 =item L<Reaction::UI::Controller::Role::Action::Object>
82 =item L<Reaction::UI::Controller::Role::Action::List>
84 =item L<Reaction::UI::Controller::Role::Action::View>
86 =item L<Reaction::UI::Controller::Role::Action::Create>
88 =item L<Reaction::UI::Controller::Role::Action::Update>
90 =item L<Reaction::UI::Controller::Role::Action::Delete>
92 =item L<Reaction::UI::Controller::Role::Action::DeleteAll>
98 See L<Reaction::Class> for authors.
102 See L<Reaction::Class> for the license.