Mango::Provider - Provider base class
package MyApp::Provider::Users; use strict; use warnings; BEGIN { use base qw/Mango::Provider/; }; __PACKAGE__->result_class('MyClass'); my $object = $provider->create(\%data);
Mango::Provider is a base abstract class for all providers used in Mango.
Creates a new provider object. If options are passed to new, those are sent to setup.
setup
my $provider = Mango::Provider->new({ result_class => 'MyResultClass' });
The following options are available at the class level, to new/setup and take the same data as their method counterparts:
result_class
Creates a new object of type result_class using the supplied data.
my $object = $provider->create({ id => 23, thingy => 'value' });
Deletes objects from the provider 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 name of the result class results should be returned as.
$provider->result_class('MyClass'); my $object = $provider->search->first; print ref $object; # MyClass
An exception will be thrown if the specified class can not be loaded.
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' });
The complete list of supported options are at the discretion each individual provider, but each provider should support the following options:
The name/direction of of the column(s) to sort the results.
{order_by => 'col asc'}
The page number of the results to return.
{page => 2}
The number of results per page to return.
{rows => 10}
When using rows/page, you can retrieve a Data::Page object from the iterator.
my $results = $provider->search(undef, { rows => 10, page => 2 }); my $pager = $results->pager; print "Page 2 of ", $pager->last_page; while (my $result = $results->next) { print $result->id; };
Calls each key as a method with the supplied value. setup is automatically called by new.
new
is the same as:
my $provider = Mango::Provider->new; $provider->setup({ result_class => 'MyResultClass' });
which is the same as:
my $provider = Mango::Provider->new; $provider->result_class('MyResultClass');
Saves any changes made to the object back to the underlying store.
my $object = $provider->create(\%data); $object->col('value'); $provider->update($object);
Gets the current class for the specified component name.
my $class = $self->get_component_class('result_class');
There is no good reason to use this. Use the specific class accessors instead.
Sets the current class for the specified component name.
$self->set_component_class('result_class', 'MyItemClass');
A Mango::Exception exception will be thrown if the specified class can not be loaded.
Mango::Iterator
Christopher H. Laco CPAN ID: CLACO claco@chrislaco.com http://today.icantfocus.com/blog/
To install Mango, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mango
CPAN shell
perl -MCPAN -e shell install Mango
For more information on module installation, please visit the detailed CPAN module installation guide.