-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Mojolicious::Plugin::AnyData
version 1.11
Mojolicious::Plugin::AnyData uses your perl-data in the memory like a database source.
use Mojolicious::Plugin::AnyData
sub startup {
my $self = shift;
$self->plugin(any_data => {
load_data => {
cars => [
['id', 'model'],
[ 1, 'Honda'], ],
},
},
helper => 'db',
});
# ... or
$self->plugin(any_data => {
func => ['cars', 'XML', 'cars.xml', 'ad_import'],
});
# ... or
$self->plugin(any_data => {
load_data => 'my_test_data.conf'
});
}
This plugin don't needs any required options, you may load data at any moment in your program, helper will turn to default value 'db' if it not specified.
You can change DBD::AnyData instance to your production database handler, just by changing a development mode to production in your project:
app->mode('production');
Mojolicious::Plugin::AnyData provides all methods available from DBD::AnyData and DBI.
A helper will be created with your specified name or 'db' by default.
On startup available two additional methods:
Load data from perl-struct (hashref) into the memory. Supports a few tables at the same time.
$self->plugin(any_data => {
load_data => {
artists => [
['id_artist', 'artist_name'],
[ 1, 'Metallica'],
[ 2, 'Dire Staits'],
],
releases => [
['id_release', 'release_name', 'id_artist'],
[ 1, 'Death Magnetic', 1],
[ 2, 'Load', 1],
],
},
});
You also can load data stuctures from separate config using Mojolicious::Plugin::Config:
$self->plugin(any_data => {
load_data => 'test_data.conf',
helper => 'db'
});
Plugin automatically checks data type (hashref or simple scalar) and then, if it simple scalar, tries to use this as a file name to load data by Mojolicious::Plugin::Config.
Runs DBD::AnyData::func method after creating AnyData-object with params:
$self->plugin(any_data => {
func => ['cars', 'XML', 'cars.xml', 'ad_import'],
});
Mojolicious, DBI, DBD::AnyData
Alexander Ponomarev, <shootnix@cpan.org>
Please report any bugs or feature requests to through the web interface at https://github.com/shootnix/Mojolicious-Plugin-AnyData/issues. If you want to contribute changes or otherwise involve yourself in development, feel free to fork the Git repository from https://github.com/shootnix/Mojolicious-Plugin-AnyData/.