
Mango::Provider::DBIC - Provider class for DBIx::Class based providers

package MyApp::Provider::Users;
use strict;
use warnings;
BEGIN {
use base qw/Mango::Provider::DBIC/;
};
__PACKAGE__->schema_class('MySchema');
__PACKAGE__->source_name('Users');
my $object = $provider->create(\%data);

Mango::Provider::DBIC is a base abstract class for all DBIx::Class based providers used in Mango.

Creates a new provider object. If options are passed to new, those are sent to setup.
my $provider = Mango::Provider::DBIC->new({
schema_class => 'MySchema',
source_name => 'Users',
result_class => 'MyResultClass'
});
The following options are available at the class level, to new/setup and take the same data as their method counterparts:
connection_info
resultset
schema
schema_class
source_name
See "new" in Mango::Provider a list of other possible options.

Gets/sets the connection information used when connecting to the database.
$provider->connection_info(['dbi:mysql:foo', 'user', 'pass', {PrintError=>1}]);
The info argument is an array ref that holds the following values:
The DBI dsn to use to connect to.
The username for the database you are connecting to.
The password for the database you are connecting to.
The attributes to be pass to DBI for this connection.
See DBI for more information about dsns and connection attributes.
Creates a new object of type result_class using the supplied data.
my $object = $provider->create({
id => 23,
thingy => 'value'
});
Deletes objects from the store matching the supplied filter.
$provider->delete({
col => 'value'
});
It can also delete an object passed into it:
$provider->delete($object);
This is the same as:
$provider->delete({ id => $object->id });
Retrieves an object from the provider matching the specified id.
my $object = $provider->get_by_id(23);
Returns undef if no matching result can be found.
Gets/sets the DBIx::Class::Resultset to be used by this provider. If no resultset is set, the resultset for the specified source_name will be created automatically.
$provider->resultset;
# same as $schema->resultset($provider->source_name)
$provider->resultset(
$schema->resultset($provder->source_name)->search({default => 'search'})
);
Gets/sets the DBIx::Class schema instance to be used for this provider. If no schema is set, a new instance of the schema_class will be created automatically when it is needed.
my $schema = $provider->schema;
$schema->dbh->{'AutoCommit'} = 0;
Gets/sets the DBIx::Class schema class to be used for this provider. An exception will be thrown if the specified class can not be loaded.
$provider->schema_class('MySchema');
my $schema = $provider->schema;
print ref $schema; # MySchema
If no schema class is specified in the subclass, the default schema class is Mango::Schema.
Returns a list of objects in list context or a Mango::Iterator in scalar context matching the specified filter.
my @objects = $provider->search({
col => 'value'
});
my $iterator = $provider->search({
col => 'value'
});
See "ATTRIBUTES" in DBIx::Class::Resultset for a list of possible options.
Gets/sets the DBIx::Class schema source to be used when creating the default resultset.
$provider->source_name('Users');
$provider->resultset;
## same as $schema->resultset('Users')
Sets the 'updated' column to DateTime->now and saves any changes made to the object back to the underlying store.
my $object = $provider->create(\%data);
$object->col('value');
$provider->update($object);


Christopher H. Laco
CPAN ID: CLACO
claco@chrislaco.com
http://today.icantfocus.com/blog/