Skip to content
shootnix edited this page Jan 3, 2012 · 9 revisions

NAME

Mojolicious::Plugin::AnyData

VERSION

version 1.14

DESCRIPTION

Mojolicious::Plugin::AnyData uses perl data in the memory like a database source.

SYNOPSIS

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'
        });
}

CONFIGURATION

This plugin doesn't require any options at startup, so you may load your data in your program at any time. The helper returns the default value 'db' if they haven't been specified before.

You can switch from DBD::AnyData instance to your production database handler by change development mode to production in your project:

app->mode('production');

METHOD/HELPERS

Mojolicious::Plugin::AnyData provides all methods inherited from DBD::AnyData and DBI.

The helper will be created with your specified name or 'db', by default.

On startup, there are two additional methods available:

load_data

It loads data from perl struct (hashref) into the memory. It can support several 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 can also load data stuctures from a separate config, using Mojolicious::Plugin::Config:

$self->plugin(any_data => {
        load_data => 'test_data.conf',
        helper    => 'db'
});

The plugin automatically checks the data type (hashref or simple scalar) and in case if it's a scalar, treats it as the file name containing data. They will be loaded automagically using Mojolicious::Plugin::Config.

func

Starts DBD::AnyData::func method after creating AnyData object with params:

$self->plugin(any_data => {
        func => ['cars', 'XML', 'cars.xml', 'ad_import'],
});

SEE ALSO

Mojolicious, DBI, DBD::AnyData

AUTHOR

Alexander Ponomarev, <shootnix@cpan.org>

BUGS/CONTRIBUTING

Please report any bugs and feature requests via the Web interface at https://github.com/shootnix/Mojolicious-Plugin-AnyData/issues. If you want to contribute, feel free to fork our Git repository https://github.com/shootnix/Mojolicious-Plugin-AnyData/.

Clone this wiki locally