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' => (is => 'ro', isa => 'ClassName', lazy_build => 1);
20 #implements BUILD => as {
22 # Class::MOP::load_class($self->_im_class);
23 # confess "_im_result_class must be a Reaction::InterfaceModel::Object"
24 # unless $self->_im_class->isa("Reaction::InterfaceModel::Object");
25 # confess "_im_result_class must have an inflate_result method"
26 # unless $self->_im_class->can("inflate_result");
31 #Oh man. I have a bad feeling about this one.
32 implements _build_member_type => as {
34 my $class = blessed($self) || $self;
35 $class =~ s/::Collection$//;
39 implements _build__collection_store => as {
41 [ $self->_source_resultset->search({}, {result_class => $self->member_type})->all ];
44 implements clone => as {
46 my $rs = $self->_source_resultset->search_rs({});
47 #should the clone include the arrayref of IM::Objects too?
48 return (blessed $self)->new(
49 _source_resultset => $rs,
50 member_type => $self->member_type, @_
54 implements count_members => as {
56 $self->_source_resultset->count;
59 implements add_member => as {
60 confess "Not yet implemented";
63 implements remove_member => as {
64 confess "Not yet implemented";
68 implements page => as {
70 my $rs = $self->_source_resultset->page(@_);
71 return (blessed $self)->new(
72 _source_resultset => $rs,
73 member_type => $self->member_type,
77 implements pager => as {
79 return $self->_source_resultset->pager(@_);
89 Reaction::InterfaceModel::Collection::DBIC::Role::Base
93 Provides methods to allow a collection to be populated by a L<DBIx::Class::ResultSet>
97 =head2 _source_resultset
99 Required, Read-only. Contains the L<DBIx::Class::ResultSet> used to populate the
104 Read-only, lazy_build. The name of the IM Object Class that the resultset inside this
105 collection will inflate to. Predicate: C<has_member_type>
111 Returns a clone of the current collection, complete with a cloned C<_source_resultset>
115 Returns the number of items found by the ResultSet
121 These will die as they have not been implemented yet.
123 =head1 PRIVATE METHODS
125 =head2 _build_im_class
127 Will attempt to remove the suffix "Collection" from the current class name and return
128 that. I.e. C<MyApp::MyIM::Roles::Collection> would return C<MyApp::MyIM::Roles>
130 =head2 _build_collection_store
132 Replace the default builder to populate the collection with all results returned by the
137 See L<Reaction::Class> for authors.
141 See L<Reaction::Class> for the license.