1 package Catalyst::Helper::Model::DBIC::Schema;
6 use UNIVERSAL::require;
10 Catalyst::Helper::Model::DBIC::Schema - Helper for DBIC Schema Models
14 script/create.pl model ModelName DBIC::Schema My::SchemaClass [ create=dynamic | create=static ] [ connect_info arguments ]
18 Helper for the DBIC Schema Models.
22 ModelName is the short name for the Model class being generated
24 My::SchemaClass is the fully qualified classname of your Schema,
25 which might or might not yet exist.
27 create=dynamic instructs this Helper to generate the named Schema
28 class for you, basing it on L<DBIx::Class::Schema::Loader> (which
29 means the table information will always be dynamically loaded at
30 runtime from the database).
32 create=static instructs this Helper to generate the named Schema
33 class for you, using L<DBIx::Class::Schema::Loader> in "one shot"
34 mode to create a standard, manually-defined L<DBIx::Class::Schema>
35 setup, based on what the Loader sees in your database at this moment.
36 A Schema/Model pair generated this way will not require
37 L<DBIx::Class::Schema::Loader> at runtime, and will not automatically
38 adapt itself to changes in your database structure. You can edit
39 the generated classes by hand to refine them.
41 connect_info arguments are the same as what DBIx::Class::Schema::connect
42 expects, and are storage_type-specific. For DBI-based storage, these
43 arguments are the dsn, username, password, and connect options,
44 respectively. These are optional for existing Schemas, but required
45 if you use either of the C<create=> options.
47 Use of either of the C<create=> options requires L<DBIx::Class::Schema::Loader>.
49 =head1 TYPICAL EXAMPLES
51 # Use DBIx::Class::Schema::Loader to create a static DBIx::Class::Schema,
52 # and a Model which references it:
53 script/myapp_create.pl model ModelName DBIC::Schema My::SchemaClass create=static dbi:mysql:foodb myuname mypass
55 # Create a dynamic DBIx::Class::Schema::Loader-based Schema,
56 # and a Model which references it:
57 script/myapp_create.pl model ModelName DBIC::Schema My::SchemaClass create=dynamic dbi:mysql:foodb myuname mypass
59 # Reference an existing Schema of any kind, and provide some connection information for ->config:
60 script/myapp_create.pl model ModelName DBIC::Schema My::SchemaClass dbi:mysql:foodb myuname mypass
62 # Same, but don't supply connect information yet (you'll need to do this
63 # in your app config, or [not recommended] in the schema itself).
64 script/myapp_create.pl model ModelName DBIC::Schema My::SchemaClass
73 my ( $self, $helper, $schema_class, @connect_info) = @_;
75 $helper->{schema_class} = $schema_class
76 or die "Must supply schema class name";
79 if($connect_info[0] && $connect_info[0] =~ /^create=(dynamic|static)$/) {
85 $helper->{setup_connect_info} = 1;
87 $_ = qq{'$_'} if $_ !~ /^\s*[[{]/;
89 $helper->{connect_info} = \@connect_info;
92 my $file = $helper->{file};
93 $helper->render_file( 'compclass', $file );
95 if($create eq 'dynamic') {
96 my @schema_parts = split(/\:\:/, $helper->{schema_class});
97 my $schema_file_part = pop @schema_parts;
99 my $schema_dir = File::Spec->catfile( $helper->{base}, 'lib', @schema_parts );
100 my $schema_file = File::Spec->catfile( $schema_dir, $schema_file_part . '.pm' );
102 $helper->mk_dir($schema_dir);
103 $helper->render_file( 'schemaclass', $schema_file );
105 elsif($create eq 'static') {
106 my $schema_dir = File::Spec->catfile( $helper->{base}, 'lib' );
107 DBIx::Class::Schema::Loader->use("dump_to_dir:$schema_dir", 'make_schema_at')
108 or die "Cannot load DBIx::Class::Schema::Loader: $@";
111 { relationships => 1 },
119 General Catalyst Stuff:
121 L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
122 L<Catalyst::Response>, L<Catalyst::Helper>, L<Catalyst>,
124 Stuff related to DBIC and this Model style:
126 L<DBIx::Class>, L<DBIx::Class::Schema>,
127 L<DBIx::Class::Schema::Loader>, L<Catalyst::Model::DBIC::Schema>,
128 L<Catalyst::Helper::Model::DBIC::SchemaLoader>
132 Brandon L Black, C<blblack@gmail.com>
136 This library is free software, you can redistribute it and/or modify
137 it under the same terms as Perl itself.
148 package [% schema_class %];
151 use base qw/DBIx::Class::Schema::Loader/;
153 __PACKAGE__->loader_options(
160 [% schema_class %] - DBIx::Class::Schema::Loader class
168 Generated by L<Catalyst::Model::DBIC::Schema> for use in L<[% class %]>
176 This library is free software, you can redistribute it and/or modify
177 it under the same terms as Perl itself.
187 use base 'Catalyst::Model::DBIC::Schema';
190 schema_class => '[% schema_class %]',
191 [% IF setup_connect_info %]connect_info => [
192 [% FOREACH arg = connect_info %][% arg %],
199 [% class %] - Catalyst DBIC Schema Model
206 L<Catalyst::Model::DBIC::Schema> Model using schema L<[% schema_class %]>
214 This library is free software, you can redistribute it and/or modify
215 it under the same terms as Perl itself.