work in progress, listview still broken
[catagits/Reaction.git] / lib / Reaction / InterfaceModel / Collection / DBIC / Role / Where.pm
1 package Reaction::InterfaceModel::Collection::DBIC::Role::Where;
2
3 use Reaction::Role;
4 use Scalar::Util qw/blessed/;
5
6 role Where, which {
7
8   #requires qw/_source_resultset _im_class/;
9   implements where => as {
10     my $self = shift;
11     my $rs = $self->_source_resultset->search_rs(@_);
12     return (blessed $self)->new(
13                                 _source_resultset => $rs,
14                                 member_type => $self->member_type
15                                );
16   };
17
18   implements add_where => as {
19     my $self = shift;
20     my $rs = $self->_source_resultset->search_rs(@_);
21     $self->_source_resultset($rs);
22     $self->_clear_collection_store if $self->_has_collection_store;
23     return $self;
24   };
25
26   #XXX may need a rename, but i needed this for ListView
27   implements find => as {
28     my $self = shift;
29     $self->_source_resultset
30       ->search({},{result_class => $self->member_type})
31         ->find(@_);
32   };
33 };
34
35 1;
36
37 =head1 NAME
38
39 Reaction::InterfaceModel::Collection::DBIC::Role::Where
40
41 =head1 DESCRIPTION
42
43 Provides methods to allow a ResultSet collection to be restricted
44
45 =head1 METHODS
46
47 =head2 where
48
49 Will return a clone with a restricted C<_source_resultset>.
50
51 =head2 add_where
52
53 Will return itself after restricting C<_source_resultset>. This also clears the
54 C<_collection_store>
55
56 =head1 AUTHORS
57
58 See L<Reaction::Class> for authors.
59
60 =head1 LICENSE
61
62 See L<Reaction::Class> for the license.
63
64 =cut