Reaction::InterfaceModel::Collection::DBIC::Role::Base - Reaction::InterfaceModel::Collection::DBIC::Role::Base documentation


Reaction documentation Contained in the Reaction distribution.

Index


Code Index:

NAME

Top

Reaction::InterfaceModel::Collection::DBIC::Role::Base

DESCRIPTION

Top

Provides methods to allow a collection to be populated by a DBIx::Class::ResultSet

Attributes

Top

_source_resultset

Required, Read-only. Contains the DBIx::Class::ResultSet used to populate the collection.

member_type

Read-only, lazy_build. The name of the IM Object Class that the resultset inside this collection will inflate to. Predicate: has_member_type

METHODS

Top

clone

Returns a clone of the current collection, complete with a cloned _source_resultset

count_members

Returns the number of items found by the ResultSet

add_member

remove_member

These will die as they have not been implemented yet.

PRIVATE METHODS

Top

_build_im_class

Will attempt to remove the suffix "Collection" from the current class name and return that. I.e. MyApp::MyIM::Roles::Collection would return MyApp::MyIM::Roles

_build_collection_store

Replace the default builder to populate the collection with all results returned by the resultset.

AUTHORS

Top

See Reaction::Class for authors.

LICENSE

Top

See Reaction::Class for the license.


Reaction documentation Contained in the Reaction distribution.

package Reaction::InterfaceModel::Collection::DBIC::Role::Base;

use Reaction::Role;
use Scalar::Util qw/blessed/;
use Class::MOP;

# WARNING - DANGER: this is just an RFC, please DO NOT USE YET

use namespace::clean -except => [ qw(meta) ];


has '_source_resultset' => (
                           is => 'ro',
                           required => 1,
                           isa => 'DBIx::Class::ResultSet',
                          );

has 'member_type' => (
                      is => 'rw', 
                      isa => 'ClassName',  
                      required => 1,
                      builder => '_build_member_type',
                      clearer => 'clear_member_type',
                      predicate => 'has_member_type',
                     );


#implements BUILD => as {
#  my $self = shift;
#  Class::MOP::load_class($self->_im_class);
#  confess "_im_result_class must be a Reaction::InterfaceModel::Object"
#    unless $self->_im_class->isa("Reaction::InterfaceModel::Object");
#  confess "_im_result_class must have an inflate_result method"
#    unless $self->_im_class->can("inflate_result");
#};



#Oh man. I have a bad feeling about this one.
sub _build_member_type {
  my $self = shift;
  my $class = blessed($self) || $self;
  $class =~ s/::Collection$//;
  return $class;
};
sub _build__collection_store {
  my $self = shift;
  [ $self->_source_resultset->search({}, {result_class => $self->member_type})->all ];
};
sub clone {
  my $self = shift;
  my $rs = $self->_source_resultset; #->search_rs({});
  #should the clone include the arrayref of IM::Objects too?
  return (blessed $self)->new(
                              _source_resultset => $rs,
                              member_type => $self->member_type, @_
                             );
};
sub count_members {
  my $self = shift;
  $self->_source_resultset->count;
};
sub add_member {
  confess "Not yet implemented";
};
sub remove_member {
  confess "Not yet implemented";
};
sub page {
  my $self = shift;
  my $rs = $self->_source_resultset->page(@_);
  return (blessed $self)->new(
                              _source_resultset => $rs,
                              member_type => $self->member_type,
                             );
};
sub pager {
  my $self = shift;
  return $self->_source_resultset->pager(@_);
};



1;