NAME
DBIx::Class::Wrapper::Factory - A factory class that decorates a DBIx::Class::ResultSet.
SYNOPSIS
A model implementing the role DBIx::Class::Wrapper will automatically instanciate subclasses of this for any underlying DBIx::Class ResultSet.
To implement your own factory containing your business code for the underlying DBIC resulsets, you need to subclass this.
PROPERTIES
dbic_rs
The original L<DBIx::Class::ResultSet>. Mandatory.
bm
The business model consuming the role DBIx::Class::Wrapper. Mandatory.
build_dbic_rs
Builds the dbic ResultSet to be wrapped by this factory. You can override this in your business specific factories to build specific resultsets.
create
Creates a new object in the DBIC Schema and return it wrapped using the wrapper method.
find
Finds an object in the DBIC schema and returns it wrapped using the wrapper method.
first
Equivalent to DBIC Resultset 'first' method.
find_or_create
Wraps around the original DBIC find_or_create method.
pager
Shortcut to underlying dbic_rs pager.
delete
Shortcut to DBIx::Class::ResultSet delete method of the underlying dbic_rs
get_column
Shortcut to the get_column of the decorated dbic_rs
search_rs
Alias for search
search
Search objects in the DBIC Schema and returns a new intance of this factory.
wrap
Wraps an DBIx::Class::Row in a business object. By default, it returns the Row itself.
Override that in your subclasses of factories if you need to wrap some business code around the DBIx::Class::Row
all
Similar to DBIC Resultset all.
Usage:
my @objs = $this->all();
loop_through
Loop through all the elements of this factory whilst paging and execute the given code with the current retrieved object.
WARNINGS:
Make sure your resultset is ordered as it wouldn't make much sense to page through an unordered resultset.
In case other things are concurrently adding to this resultset, it is possible that the code you give will be called with the same objects twice.
If it's not the problem and if the rate at which objects are added is not too fast compared to the processing you are doing in the code, it should be just fine.
In other cases, you probably want to wrap this in a transaction to have a frozen view of the resultset.
Usage:
$this->loop_through(sub{ my $o = shift ; do something with o });
$this->loop_through(sub{...} , { limit => 1000 }); # Do only 1000 calls to sub.
$this->loop_through(sub{...} , { rows => 20 }); # Go by pages of 20 rows
next
Returns next Business Object from this current DBIx::Resultset.
count
Returns the number of objects in this ResultSet.