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',
23 #implements BUILD => as {
25 # Class::MOP::load_class($self->_im_class);
26 # confess "_im_result_class must be a Reaction::InterfaceModel::Object"
27 # unless $self->_im_class->isa("Reaction::InterfaceModel::Object");
28 # confess "_im_result_class must have an inflate_result method"
29 # unless $self->_im_class->can("inflate_result");
32 #Oh man. I have a bad feeling about this one.
33 implements _build_im_class => as {
35 my $class = blessed $self || $self;
36 $class =~ s/::Collection$//;
40 implements _build_collection_store => as {
42 my $im_class = $self->_im_class;
43 [ $self->_source_resultset->search({}, {result_class => $im_class})->all ];
46 implements clone => as {
48 my $rs = $self->_source_resultset->search_rs({});
49 #should the clone include the arrayref of IM::Objects too?
50 return (blessed $self)->new(
51 _source_resultset => $rs,
52 _im_class => $self->_im_class, @_
56 implements count_members => as {
58 $self->_source_resultset->count;
61 implements add_member => as {
62 confess "Not yet implemented";
65 implements remove_member => as {
66 confess "Not yet implemented";
70 implements page => as {
72 my $rs = $self->_source_resultset->page(@_);
73 return (blessed $self)->new(
74 _source_resultset => $rs,
75 _im_class => $self->_im_class,
79 implements pager => as {
81 return $self->_source_resultset->pager(@_);
91 Reaction::InterfaceModel::Collection::DBIC::Role::Base
95 Provides methods to allow a collection to be populated by a L<DBIx::Class::ResultSet>
99 =head2 _source_resultset
101 Required, Read-only. Contains the L<DBIx::Class::ResultSet> used to populate the
106 Read-only, lazy_build. The name of the IM Object Class that the resultset inside this
107 collection will inflate to. Predicate: C<_has_im_class>
113 Returns a clone of the current collection, complete with a cloned C<_source_resultset>
117 Returns the number of items found by the ResultSet
123 These will die as they have not been implemented yet.
125 =head1 PRIVATE METHODS
127 =head2 _build_im_class
129 Will attempt to remove the suffix "Collection" from the current class name and return
130 that. I.e. C<MyApp::MyIM::Roles::Collection> would return C<MyApp::MyIM::Roles>
132 =head2 _build_collection_store
134 Replace the default builder to populate the collection with all results returned by the
139 See L<Reaction::Class> for authors.
143 See L<Reaction::Class> for the license.