Articulate

 view release on metacpan or  search on metacpan

lib/Articulate/Storage/DBIC/Simple.pm  view on Meta::CPAN

package Articulate::Storage::DBIC::Simple;
use strict;
use warnings;

use Moo;
with 'Articulate::Role::Component';
with 'Articulate::Role::Storage';
use Articulate::Syntax;
use JSON;
use Scalar::Util qw(blessed);

=head1 NAME

Articulate::Content::DBIC::Simple - store your content in a simple
database

=cut

=head1 DESCRIPTION

This content storage interface works by placing content and metadata in
a database table, to which it connects using L<DBIx::Class>.

All content items are stored in a single table defined in
L<Articulate::Storage::DBIC::Simple::Schema::Result::Articulate::Item>,
and rows contain meta, content and location. Meta is stored in JSON.

It is left up to the application, not the database to maintain
referential integrity (although there is a rudimentary cascade deletion
for descendant items).

On the other hand, you can make changes to your dat structure freely
without making schema changes.

By default, this will create an SQLite database in memory and deploy
the schema (i.e. no persistence), but you can alter this using the
C<schema> attribute. You can also make your own schema, provided it is
a superset of the existing schema.

=cut

=head1 ATTRIBUTE

=head3 schema

  components:
    Articulate::Storage::DBIC::Simple:
      schema:
        class: Articulate::Storage::DBIC::Simple::Schema
        constructor: connect
        args:
          - dbi:SQLite:somefile.db
          - user_name
          - notverysecretpassword

Allows you to specify how to connect to your database. By default, it
connects to an SQLite :memory: DB and uses the connect_and_deploy
constructor from the L<Articulate::Storage::DBIC::Simple::Schema>
schema.

=cut

has schema => (
  is      => 'rw',
  default => sub {
    return {
      class       => 'Articulate::Storage::DBIC::Simple::Schema',
      constructor => 'connect_and_deploy',
      args        => [ 'dbi:SQLite::memory:', '', '' ],
    };
  },
  coerce => sub {
    instantiate $_[0],;
  },
);

=head1 METHODS

=cut

sub dbic_find { # internal method
  my $self      = shift;
  my $location  = shift;
  my $dbic_item = $self->schema->resultset('Articulate::Item')
    ->find( { location => "$location" } );
}

sub dbic_to_real { # internal method
  my $self      = shift;



( run in 2.185 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )