1 package Catalyst::Helper::Model::DBIC::Schema;
9 Catalyst::Helper::Model::DBIC::Schema - Helper for DBIC Schema Models
13 script/create.pl model ModelName DBIC::Schema My::SchemaClass [ create=dynamic | create=static ] [ connect_info arguments ]
17 Helper for the DBIC Schema Models.
21 ModelName is the short name for the Model class being generated
23 My::SchemaClass is the fully qualified classname of your Schema,
24 which might or might not yet exist.
26 create=dynamic instructs this Helper to generate the named Schema
27 class for you, basing it on L<DBIx::Class::Schema::Loader> (which
28 means the table information will always be dynamically loaded at
29 runtime from the database).
31 create=static instructs this Helper to generate the named Schema
32 class for you, using L<DBIx::Class::Schema::Loader> in "one shot"
33 mode to create a standard, manually-defined L<DBIx::Class::Schema>
34 setup, based on what the Loader sees in your database at this moment.
35 A Schema/Model pair generated this way will not require
36 L<DBIx::Class::Schema::Loader> at runtime, and will not automatically
37 adapt itself to changes in your database structure. You can edit
38 the generated classes by hand to refine them.
40 connect_info arguments are the same as what DBIx::Class::Schema::connect
41 expects, and are storage_type-specific. For DBI-based storage, these
42 arguments are the dsn, username, password, and connect options,
43 respectively. These are optional for existing Schemas, but required
44 if you use either of the C<create=> options.
46 Use of either of the C<create=> options requires L<DBIx::Class::Schema::Loader>.
48 =head1 TYPICAL EXAMPLES
50 # Use DBIx::Class::Schema::Loader to create a static DBIx::Class::Schema,
51 # and a Model which references it:
52 script/myapp_create.pl model ModelName DBIC::Schema My::SchemaClass create=static dbi:mysql:foodb myuname mypass
54 # Create a dynamic DBIx::Class::Schema::Loader-based Schema,
55 # and a Model which references it:
56 script/myapp_create.pl model ModelName DBIC::Schema My::SchemaClass create=dynamic dbi:mysql:foodb myuname mypass
58 # Reference an existing Schema of any kind, and provide some connection information for ->config:
59 script/myapp_create.pl model ModelName DBIC::Schema My::SchemaClass dbi:mysql:foodb myuname mypass
61 # Same, but don't supply connect information yet (you'll need to do this
62 # in your app config, or [not recommended] in the schema itself).
63 script/myapp_create.pl model ModelName DBIC::Schema My::SchemaClass
72 my ( $self, $helper, $schema_class, @connect_info) = @_;
74 $helper->{schema_class} = $schema_class
75 or die "Must supply schema class name";
78 if($connect_info[0] && $connect_info[0] =~ /^create=(dynamic|static)$/) {
84 $helper->{setup_connect_info} = 1;
86 $_ = qq{'$_'} if $_ !~ /^\s*[[{]/;
88 $helper->{connect_info} = \@connect_info;
91 my $file = $helper->{file};
92 $helper->render_file( 'compclass', $file );
94 if($create eq 'dynamic') {
95 my @schema_parts = split(/\:\:/, $helper->{schema_class});
96 my $schema_file_part = pop @schema_parts;
98 my $schema_dir = File::Spec->catfile( $helper->{base}, 'lib', @schema_parts );
99 my $schema_file = File::Spec->catfile( $schema_dir, $schema_file_part . '.pm' );
101 $helper->mk_dir($schema_dir);
102 $helper->render_file( 'schemaclass', $schema_file );
104 elsif($create eq 'static') {
105 die "Unimplemented ...";
106 # XXX make a loader class in memory with dumpdir set to our base+lib, and load it.
112 General Catalyst Stuff:
114 L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
115 L<Catalyst::Response>, L<Catalyst::Helper>, L<Catalyst>,
117 Stuff related to DBIC and this Model style:
119 L<DBIx::Class>, L<DBIx::Class::Schema>,
120 L<DBIx::Class::Schema::Loader>, L<Catalyst::Model::DBIC::Schema>,
121 L<Catalyst::Helper::Model::DBIC::SchemaLoader>
125 Brandon L Black, C<blblack@gmail.com>
129 This library is free software, you can redistribute it and/or modify
130 it under the same terms as Perl itself.
141 package [% schema_class %];
144 use base qw/DBIx::Class::Schema::Loader/;
146 __PACKAGE__->loader_options(
153 [% schema_class %] - DBIx::Class::Schema::Loader class
161 Generated by L<Catalyst::Model::DBIC::Schema> for use in L<[% class %]>
169 This library is free software, you can redistribute it and/or modify
170 it under the same terms as Perl itself.
180 use base 'Catalyst::Model::DBIC::Schema';
183 schema_class => '[% schema_class %]',
184 [% IF setup_connect_info %]connect_info => [
185 [% FOREACH arg = connect_info %][% arg %],
192 [% class %] - Catalyst DBIC Schema Model
199 L<Catalyst::Model::DBIC::Schema> Model using schema L<[% schema_class %]>
207 This library is free software, you can redistribute it and/or modify
208 it under the same terms as Perl itself.