The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

Name

CatalystX::Usul::Schema - Support for database schemas

Version

0.6.$Revision: 1165 $

Synopsis

   package CatalystX::Usul::Model::Schema;

   use parent qw(Catalyst::Model::DBIC::Schema
                 CatalystX::Usul::Model
                 CatalystX::Usul::Schema);

   package YourApp::Model::YourModel;

   use parent qw(CatalystX::Usul::Model::Schema);

   __PACKAGE__->config( database     => q(library),
                        schema_class => q(YourApp::Schema::YourSchema) );

   sub COMPONENT {
      my ($class, $app, $config) = @_;

      $config->{database    } ||= $class->config->{database};
      $config->{connect_info} ||=
         $class->get_connect_info( $app, $config->{database} );

      return $class->next::method( $app, $config );
   }

Description

Provides utility methods to classes inheriting from DBIx::Class::Schema

The encryption/decryption methods only obscure the database password from casual viewing, they do not in any way secure it

Configuration and Environment

The XML data looks like this:

  <credentials>
    <name>database_we_want_to_connect_to</name>
    <driver>mysql</driver>
    <host>localhost</host>
    <password>encrypt=0QqX325DLs18I8T/wU4/ZQQ=</password>
    <port>3306</port>
    <print_error>0</print_error>
    <raise_error>1</raise_error>
    <user>root</user>
  </credentials>

Subroutines/Methods

schema_init

Called from the constructor of YourApp::Schema this method initialiases the attributes used by the other methods

create_database

Creates a database. Understands how to do this for different RDBMSs, e.g. MySQL and PostgreSQL

create_ddl

Dump the database schema definition

create_schema

Creates a database then deploys and populates the schema

decrypt

   my $plain = $self->decrypt( $seed, $encoded );

Decodes and decrypts the $encoded argument and returns the plain text result. See the "encrypt" method

deploy_and_populate

Create database tables and populate them with initial data. Called as part of the application install

drop_database

Drops the database that is selected by the call to "get_connect_info"

get_connect_info

   my $db_info_arr = $self->get_connect_info( $config, $database );

Returns an array ref containing the information needed to make a connection to a database; DSN, user id, password, and options hash ref. The data is read from the XML file in the config ctrldir. Multiple sets of data can be stored in the same file, keyed by the $database argument. The password is decrypted if required. The password decrpytion can be seeded from a text file in the ctrldir

encrypt

   my $encrypted = $self->encrypt( $seed, $plain );

Encrypts the plain text passed in the $plain argument and returns it Base64 encoded. Crypt::Twofish_PP is used to do the encryption. The $seed argument is passed to the "_keygen" method

Private Methods

_edit_credentials

   $self->_edit_credentials( $config );

Writes the database login information stored in the $config to the application config file in the var/etc directory. Called from "create_schema"

_encrypt_for_cfg

   $encrypted_value = $self->_encrypt_for_conf( $config, $plain )

Returns the encrypted value of the plain value prefixed appropriately for storage in a config file. Called from "_edit_credentials"

_keygen

Generates the key used by the "encrypt" and "decrypt" methods. Calls "_inflate" to create the salt. Note that the salt is eval'd in string context

Private Subroutines

__inflate

Lifted from Acme::Bleach this recovers the default salt for the key generator

Diagnostics

None

Dependencies

CatalystX::Usul::Base
CatalystX::Usul::File
Crypt::CBC
Crypt::Twofish

Incompatibilities

There are no known incompatibilities in this module

Bugs and Limitations

There are no known bugs in this module. Please report problems to the address below. Patches are welcome

Author

Peter Flanigan, <Support at RoxSoft.co.uk>

License and Copyright

Copyright (c) 2011 Peter Flanigan. All rights reserved

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic

This program is distributed in the hope that it will be useful, but WITHOUT WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE