NAME

App::AutoCRUD::ConfigDomain - checking configuration data

SYNOPSIS

Using the module

use App::AutoCRUD::ConfigDomain;
use YAML qw/LoadFile Dump/;

my $config = LoadFile $config_file;
my $domain = App::AutoCRUD::ConfigDomain->Config();
my $errors = $domain->inspect($config);
die Dump($errors) if $errors;

Configuration example

app:
  # global settings for the application
  # maybe application name, stuff for the homepage, etc.
  name: Demo
  title: AutoCRUD demo application
  readonly: 0
  default:
      page_size : 50

datasources :
  Chinook :
    dbh:
      connect:
        - "dbi:SQLite:dbname=Chinook_Sqlite_AutoIncrementPKs.sqlite"
        - ""
        - ""
        - RaiseError: 1
          sqlite_unicode: 1
          sqlite_open_flags: 2 # SQLITE_OPEN_READWRITE

    tablegroups :
      - name: Music
        descr: Tables describing music content
        node: open
        tables :
          - Artist
          - Album
          - Track

      - name: Playlist
        descr: Tables for structuring playlists
        node: open
        tables :
          - Playlist
          - PlaylistTrack

      # ...

    tables:
      Track:
        colgroups:
          - name: keys
            columns:
              - name: TrackId
                descr: Primary key
              - name: AlbumId
                descr: foreign key to the album where this track belongs
              - name: GenreId
                descr: foreign key to the genre of this track
              - name: MediaTypeId
                descr: foreign key to the media type of this track
          - name: Textual information
            columns:
              - name: Name
                descr: name of this track
              - name: Composer
                descr: name of composer of this track
          - name: Technical details
            columns:
              - name: Bytes
              - name: Milliseconds
          - name: Commercial details
            columns:
              - name: UnitPrice

      Customer:
        colgroups:
          - name: keys
            columns:
              - name: CustomerId
                descr: Primary key
              - name: SupportRepId
                descr: foreign key to the support employee
          - name: Name
            columns:
              - name: FirstName
              - name: LastName
              - name: Company
          - name: Address
            columns:
              - name: Address
              - name: PostalCode
              - name: City
              - name: State
              - name: Country
          - name: Other coordinates
            columns:
              - name: Email
              - name: Fax
              - name: Phone

      # ...

DESCRIPTION

This package builds a Data::Domain for checking configuration data.

The App::AutoCRUD application uses this domain at startup time to check if the configuration is correct.

DATASTRUCTURE

<config> : {
  app         => <app>,
  datasources => [ <datasource>+ ]
}

<app> : {
  name        => <string>,
  title       => <string>,
  readonly    => <whatever>, # used as boolean
  default     => <hashref>,
}

<datasource> : {
  dbh => {
    connect    => ( [ <string>, <string>, <string>, <hashref>? ]
                   | <coderef> ),
    db_catalog => <string>,
    db_schema  => <string>,
  },
  descr        => <string>,
  require      => <string>,
  schema_class => <string>,
  tablegroups  => [ <tablegroup>+ ],
  tables       => [ <table>+ ],
  filters      => { [ include => <string>, ] [exclude => <string>] }
}

<tablegroup> : {
  name => string,
  [ descr => string, ]
  [ node  => 'open' | 'closed', ]
  tables  => <string>+

<table> : {
  <string> => {
    [ descr => <string>, ]
    colgroups => {
      name => <string>
      [ descr => string, ]
      [ node  => 'open' | 'closed', ]
      columns => {
        name => <string>,
        [ descr => <string> ]
      }+
    }+
  }

CONFIGURATION SECTIONS

app

Basic information about the application :

name

Short name (will be displayed in most pages).

title

Long name (will be displayed in home page).

readonly

Boolean flag; if true, data mutation operations will be forbidden (i.e. no insert, update or delete).

default

Hashref of various default values that may be used by inner modules. Currently there is only one example : page_size, used by App::AutoCRUD::Controller::Table to decide how many records per page will be displayed.

datasources

datasources :
  Chinook :
    dbh:
      connect:
        - "dbi:SQLite:dbname=/path/to/Chinook_Sqlite_AutoIncrementPKs.sqlite"
        - ""                  # username
        - ""                  # password
        - RaiseError: 1       # DBI options
          sqlite_unicode: 1

A hashref describing the various databases served by this application. Each key in the hashref is a short name for accessing the corresponding datasource; that name will be part of URLs. Each value is a hashref with the following keys :

dbh

A hashref containing instructions for connecting to the database.

The main key is connect, which contains a list of arguments to "connect" in DBI, i.e. a connection string, username, password, and possibly a hashref of additional options. Alternatively, connect could also contain a coderef, or even just a string of Perl code, which will be evaled to get the connection.

Optional keys db_catalog and db_schema may specify the values to be passed to "table_info" in DBI, "column_info" in DBI, etc. This will be necessary if your database contains several catalogs and/or schemata.

descr

A string for describing the database; this will be displayed on the home page.

require

The name of a Perl module to load before accessing this datasource (optional).

schema_class

The name of the DBIx::DataModel::Schema subclass for this datasource. This is optional, and defaults to the value of require; if none is supplied, the class will be constructed dynamically.

tablegroups
tablegroups :
  - name: Music
    descr: Tables describing music content
    node: open
    tables :
      - Artist
      - Album
      - Track
  - name: Reference
    descr: Lists of codes
    node: closed
    tables :
      - MediaType
      - Genre
  ...

Datastructure for organising how database tables will be presented. In absence of groups, the default presentation is alphabetical order, which is good enough for small databases, but is no longer appropriate when the number of tables becomes large. Tablegroups is a list of subsets of tables; each group may contain :

name

Short name for this group

descr

Longer description for this group

node

Either open or closed, depending on how you want this group to be presented in the home page. By default groups are open, which means that the list of tables within the group is immediately visible. The choice closed is more appropriate for tables which contain technical information and are not immediately useful to the user.

tables

The ordered list of tables within this group.

filters

Allows to hide some tables by using inclusion and/or exclusion regexes. These rules only apply to tables to tables NOT explicitely defined in the configuration.

These rules are for display comfort, not for security : tables hidden from display remain accessible through the URL API, if the proper URL is supplied by hand.

include

Only tables matching this regex will be displayed.

exclude

Tables matching this regex will not be displayed. Exclude takes precedence over include.