CatalystX::Usul::Model::Schema - Base class for database models


CatalystX-Usul documentation Contained in the CatalystX-Usul distribution.

Index


Code Index:

Name

Top

CatalystX::Usul::Model::Schema - Base class for database models

Version

Top

0.3.$Revision: 583 $

Synopsis

Top

   package YourApp::Model::YourModel;

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

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

   sub new {
      my ($class, $app, @rest) = @_;

      my $database = $rest[0]->{database} || $class->config->{database};

      $class->config( connect_info
                         => $class->connect_info( $app, $database ) );

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

Description

Top

Aggregates the methods from the three classes it inherits from

Subroutines/Methods

Top

build_per_context_instance

Adds the attributes from CatalystX::Usul::Model to the ones from Catalyst::Model::DBIC::Schema

connect_info

Calls parent method to obtain dsn, user and password information from configuration file before instantiating the database classes

Diagnostics

Top

None

Configuration and Environment

Top

None

Dependencies

Top

Catalyst::Model::DBIC::Schema
CatalystX::Usul::Model
CatalystX::Usul::Schema

Incompatibilities

Top

There are no known incompatibilities in this module

Bugs and Limitations

Top

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

Author

Top

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

License and Copyright

Top


CatalystX-Usul documentation Contained in the CatalystX-Usul distribution.

# @(#)$Id: Schema.pm 583 2009-06-12 14:17:22Z pjf $

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

use strict;
use warnings;
use version; our $VERSION = qv( sprintf '0.3.%d', q$Rev: 583 $ =~ /\d+/gmx );
use parent qw(Catalyst::Model::DBIC::Schema
              CatalystX::Usul::Model
              CatalystX::Usul::Schema);

use Class::C3;

sub build_per_context_instance {
   my ($self, $c, @rest) = @_;

   my $new   = $self->next::method( $c, @rest );
   my $model = $c->model( q(Base) );

   $new->{ $_ } = $model->{ $_ } for (keys %{ $model });

   return $new;
}

sub connect_info {
   my ($self, $app, $db) = @_; my ($args, $dir, $info, $path);

   if ($db and $dir = $app->config->{ctrldir}) {
      $path = $self->catfile( $dir, $app->config->{prefix}.q(.txt) );
      $args = { seed => $app->config->{secret} || $app->config->{prefix} };
      $args->{data} = $self->io( $path )->all if (-f $path);
      $info = $self->next::method( $self->catfile( $dir, $db.q(.xml) ),
                                   $db, $args );
   }
   else { $app->log->error( "${self}: No database or directory\n" ) }

   return $info;
}

1;

__END__

# Local Variables:
# mode: perl
# tab-width: 3
# End: