1 package Reaction::InterfaceModel::Collection::DBIC::Role::Base;
4 use Scalar::Util qw/blessed/;
7 # WARNING - DANGER: this is just an RFC, please DO NOT USE YET
11 has '_source_resultset' => (
14 isa => 'DBIx::Class::ResultSet',
17 has 'member_type' => (
21 builder => '_build_member_type',
22 clearer => 'clear_member_type',
23 predicate => 'has_member_type',
27 #implements BUILD => as {
29 # Class::MOP::load_class($self->_im_class);
30 # confess "_im_result_class must be a Reaction::InterfaceModel::Object"
31 # unless $self->_im_class->isa("Reaction::InterfaceModel::Object");
32 # confess "_im_result_class must have an inflate_result method"
33 # unless $self->_im_class->can("inflate_result");
38 #Oh man. I have a bad feeling about this one.
39 implements _build_member_type => as {
41 my $class = blessed($self) || $self;
42 $class =~ s/::Collection$//;
46 implements _build__collection_store => as {
48 [ $self->_source_resultset->search({}, {result_class => $self->member_type})->all ];
51 implements clone => as {
53 my $rs = $self->_source_resultset; #->search_rs({});
54 #should the clone include the arrayref of IM::Objects too?
55 return (blessed $self)->new(
56 _source_resultset => $rs,
57 member_type => $self->member_type, @_
61 implements count_members => as {
63 $self->_source_resultset->count;
66 implements add_member => as {
67 confess "Not yet implemented";
70 implements remove_member => as {
71 confess "Not yet implemented";
75 implements page => as {
77 my $rs = $self->_source_resultset->page(@_);
78 return (blessed $self)->new(
79 _source_resultset => $rs,
80 member_type => $self->member_type,
84 implements pager => as {
86 return $self->_source_resultset->pager(@_);
96 Reaction::InterfaceModel::Collection::DBIC::Role::Base
100 Provides methods to allow a collection to be populated by a L<DBIx::Class::ResultSet>
104 =head2 _source_resultset
106 Required, Read-only. Contains the L<DBIx::Class::ResultSet> used to populate the
111 Read-only, lazy_build. The name of the IM Object Class that the resultset inside this
112 collection will inflate to. Predicate: C<has_member_type>
118 Returns a clone of the current collection, complete with a cloned C<_source_resultset>
122 Returns the number of items found by the ResultSet
128 These will die as they have not been implemented yet.
130 =head1 PRIVATE METHODS
132 =head2 _build_im_class
134 Will attempt to remove the suffix "Collection" from the current class name and return
135 that. I.e. C<MyApp::MyIM::Roles::Collection> would return C<MyApp::MyIM::Roles>
137 =head2 _build_collection_store
139 Replace the default builder to populate the collection with all results returned by the
144 See L<Reaction::Class> for authors.
148 See L<Reaction::Class> for the license.