Catalyst::Helper::Model::InstantCRUD - Catalyst::Helper::Model::InstantCRUD documentation
package Catalyst::Helper::Model::InstantCRUD;
our $VERSION = '0.03';
use warnings;
use strict;
use Carp;
use Path::Class;
use Catalyst::Example::InstantCRUD::Utils;
use Data::Dumper;
sub mk_compclass {
my ( $self, $helper, $schema, $dsn, $user, $password, $options, $attrs ) =
@_;
my $schemaclass = $helper->{app} . "::$schema";
# Create the DBIC Schema Model
$helper->mk_component( $helper->{app}, 'model', $helper->{name},
'DBIC::Schema', $schemaclass, $dsn, $user, $password );
$attrs ||= Catalyst::Example::InstantCRUD::Utils->load_schema(
dsn => $dsn,
user => $user,
password => $password
);
my $schemadir = file( $helper->{file} )->parent->parent->subdir($schema);
$helper->mk_dir( $schemadir );
# Schema classes
$helper->{schema} = $schemaclass;
my @classes;
for my $table ( keys %{ $attrs->{tables} } ) {
$helper->{package} = $helper->{app} . "::" . $attrs->{tables}{$table}{c};
$helper->{class} = $attrs->{tables}{$table}{c};
$helper->{relationships} = $attrs->{rels}{ $helper->{class} };
#my %elements = map { $_ => 1 } @{$attrs->{elems}{$helper->{class}}};
my %elements = map { $_ => 1 } @{ $attrs->{tables}{$table}{qw/cols/} },
@{ $attrs->{tables}{$table}{qw/relationships/} };
$helper->{elements} = join ' ', keys %elements;
$helper->{pks} = join ' ', @{ $attrs->{tables}{$table}{pks} };
$helper->{overload_method} = $attrs->{tables}{$table}{overload_method};
$helper->{columns} = $attrs->{tables}{$table}{columns};
$helper->{table} = $table;
my $source = $attrs->{tables}{$table}{source};
push @classes, $source;
my $file = dir( $schemadir, "$source.pm" );
$helper->render_file( schemaclass => $file );
}
# Schema base class
my $file = dir( $schemadir, 'base.pm' );
$helper->render_file( baseclass => $file );
# Schema class
$helper->{classes} = join ' ', @classes;
$file = $schemadir . ".pm";
$helper->render_file( schema => $file );
return 1;
}
# No test file
sub mk_comptest { }
1;
__DATA__