1 package Catalyst::Helper::Model::DBIC::SchemaLoader;
9 Catalyst::Helper::Model::DBIC::SchemaLoader - Helper for AutoLoaded DBIC Schema Models
13 script/myapp_create.pl model Foo DBIC::SchemaLoader dsn user password
16 Foo is the short name for the Model class being generated
17 dsn, user, and password are the connection info
21 This helper generates two classes:
23 First, it generates a L<DBIx::Class::Schema::Loader> class at
24 F<lib/MyApp/SchemaLoader/Foo.pm> based on your supplied dsn/user/pass.
26 Then, it generates a L<Catalyst::Model::DBIC::Schema> at
27 F<lib/MyApp/M/Foo.pm>, which references the above-generated loader.
29 Models generated by this Helper require the seperate package
30 L<DBIx::Class::Schema::Loader> to be installed. It is on the recommended
31 list for this package, but is not required for installation.
40 my ( $self, $helper, $dsn, $user, $pass ) = @_;
42 $helper->{loader_class} = $helper->{class};
43 $helper->{loader_class} =~ s/\:\:M(?:odel)?\:\:/::SchemaLoader::/;
44 my @loader_parts = split(/\:\:/, $helper->{loader_class});
45 my $loader_file_part = pop @loader_parts;
47 my $loader_dir = File::Spec->catfile( $helper->{base}, 'lib', @loader_parts );
48 my $loader_file = File::Spec->catfile( $loader_dir, $loader_file_part . '.pm' );
50 $helper->mk_dir($loader_dir);
52 $helper->{dsn} = $dsn || '';
53 $helper->{user} = $user || '';
54 $helper->{pass} = $pass || '';
56 $helper->mk_dir( $loader_dir );
57 $helper->render_file( 'loaderclass', $loader_file );
60 my $file = $helper->{file};
61 $helper->render_file( 'compclass', $file );
66 General Catalyst Stuff:
68 L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
69 L<Catalyst::Response>, L<Catalyst::Helper>, L<Catalyst>,
71 Stuff related to DBIC and this Model style:
73 L<DBIx::Class>, L<DBIx::Class::Schema>,
74 L<DBIx::Class::Schema::Loader>, L<Catalyst::Model::DBIC::Schema>,
75 L<Catalyst::Helper::Model::DBIC::Schema>
79 Brandon L Black, C<blblack@gmail.com>
83 This library is free software, you can redistribute it and/or modify
84 it under the same terms as Perl itself.
95 package [% loader_class %];
98 use base qw/DBIx::Class::Schema::Loader/;
100 __PACKAGE__->load_from_connection(
102 user => '[% user %]',
103 pass => '[% pass %]',
107 ShowErrorStatement => 1,
117 [% loader_class %] - Loader-generated DBIx::Class::Schema class
125 Generated by L<Catalyst::Model::DBIC::Schema> for use in L<[% class %]>
133 This library is free software, you can redistribute it and/or modify
134 it under the same terms as Perl itself.
144 use base 'Catalyst::Model::DBIC::Schema';
147 schema_class => '[% loader_class %]',
152 [% class %] - Catalyst DBIC Schema Model
160 L<Catalyst::Model::DBIC::Schema> Model using L<DBIx::Class::Schema::Loader>
161 generated Schema: L<[% loader_class %]>
169 This library is free software, you can redistribute it and/or modify
170 it under the same terms as Perl itself.