C::M::DBIC::Schema - cleanups
[catagits/Catalyst-Model-DBIC-Schema.git] / lib / Catalyst / Helper / Model / DBIC / Schema.pm
index 1ca4135..b0f967e 100644 (file)
@@ -25,8 +25,9 @@ Catalyst::Helper::Model::DBIC::Schema - Helper for DBIC Schema Models
 =head1 SYNOPSIS
 
   script/create.pl model CatalystModelName DBIC::Schema MyApp::SchemaClass \
-    [ create=dynamic | create=static ] [ Schema::Loader opts ] \
-    [ dsn user pass ] [ other connect_info arguments ]
+    [ create=dynamic | create=static ] [ roles=role1,role2... ] \
+    [ Schema::Loader opts ] [ dsn user pass ] \
+    [ other connect_info args ]
 
 =head1 DESCRIPTION
 
@@ -56,6 +57,11 @@ L<DBIx::Class::Schema::Loader> at runtime, and will not automatically
 adapt itself to changes in your database structure.  You can edit
 the generated classes by hand to refine them.
 
+C<roles> is the list of roles to apply to the model, see
+L<Catalyst::Model::DBIC::Schema> for details.
+
+C<Schema::Loader opts> are described in L</TYPICAL EXAMPLES> below.
+
 C<connect_info> arguments are the same as what
 DBIx::Class::Schema::connect expects, and are storage_type-specific.
 For DBI-based storage, these arguments are the dsn, username,
@@ -103,6 +109,9 @@ Use of either of the C<create=> options requires L<DBIx::Class::Schema::Loader>.
 
 =head2 mk_compclass
 
+This is called by L<Catalyst::Helper> with the commandline args to generate the
+files.
+
 =cut
 
 sub mk_compclass {
@@ -117,10 +126,17 @@ sub mk_compclass {
     $self->helper($helper);
 
     my $create = '';
-    if ($args[0] && $args[0] =~ /^create=(dynamic|static)$/) {
+    if ($args[0] && $args[0] =~ /^create=(dynamic|static)\z/) {
         $create = $1;
         shift @args;
 
+        if ($args[0] && $args[0] =~ /^roles=(.*)\z/) {
+            $helper->{roles} = '['
+                .(join ',' => map { qq{'$_'} } (split /,/ => $1))
+                .']';
+            shift @args;
+        }
+
         if (@args) {
             $self->_parse_loader_args(\@args);
 
@@ -157,7 +173,7 @@ sub _parse_loader_args {
         next if $key =~ /^(?:components|constraint|exclude)\z/;
 
         $loader_args{$key} = eval $val;
-        die "syntax error for loader args key '$key' with value '$val': $@"
+        croak "syntax error for loader args key '$key' with value '$val': $@"
             if $@;
     }
 
@@ -254,7 +270,7 @@ sub _build_helper_connect_info {
     for (@connect_info) {
         if (/^\s*{.*}\s*\z/) {
             my $hash = eval $_;
-            die "Syntax errorr in connect_info hash: $_: $@" if $@;
+            croak "Syntax errorr in connect_info hash: $_: $@" if $@;
             my %hash = %$hash;
 
             for my $key (keys %hash) {
@@ -304,7 +320,7 @@ sub _parse_connect_info {
     for (@connect_info) {
         if (/^\s*{.*}\s*\z/) {
             my $hash = eval $_;
-            die "Syntax errorr in connect_info hash: $_: $@" if $@;
+            croak "Syntax errorr in connect_info hash: $_: $@" if $@;
 
             %connect_info = (%connect_info, %$hash);
 
@@ -314,7 +330,7 @@ sub _parse_connect_info {
         my ($key, $val) = split /=/, $_, 2;
 
         $connect_info{$key} = eval $val;
-        die "syntax error for connect_info key '$key' with value '$val': $@"
+        croak "syntax error for connect_info key '$key' with value '$val': $@"
             if $@;
     }
 
@@ -353,7 +369,7 @@ sub _gen_dynamic_schema {
 sub _gen_static_schema {
     my $self = shift;
 
-    die "cannot load schema without connect info" unless $self->connect_info;
+    croak "cannot load schema without connect info" unless $self->connect_info;
 
     my $helper = $self->helper;
 
@@ -413,6 +429,10 @@ L<DBIx::Class::Schema::Loader>, L<Catalyst::Model::DBIC::Schema>
 
 Brandon L Black, C<blblack@gmail.com>
 
+Contributors:
+
+Rafael Kitover, C<<rkitover at cpan.org>>
+
 =head1 LICENSE
 
 This library is free software, you can redistribute it and/or modify
@@ -476,6 +496,7 @@ use base 'Catalyst::Model::DBIC::Schema';
 
 __PACKAGE__->config(
     schema_class => '[% schema_class %]',
+    [% IF roles %]roles => [% roles %],[% END %]
     [% IF setup_connect_info %]connect_info => {
         [%- FOREACH key = connect_info.keys %]
         [% key %] => [% connect_info.${key} %],