release for 0.07, ->require and connect_info args stuff
[catagits/Catalyst-Model-DBIC-Schema.git] / lib / Catalyst / Helper / Model / DBIC / SchemaLoader.pm
CommitLineData
1aeb6e1e 1package Catalyst::Helper::Model::DBIC::SchemaLoader;
7b39f3f0 2
3use strict;
4use warnings;
5use Carp;
6
7=head1 NAME
8
1aeb6e1e 9Catalyst::Helper::Model::DBIC::SchemaLoader - Helper for AutoLoaded DBIC Schema Models
7b39f3f0 10
11=head1 SYNOPSIS
12
0b2a7108 13 script/myapp_create.pl model Foo DBIC::SchemaLoader [ connect info arguments ]
7b39f3f0 14
0b2a7108 15 Where:
16 Foo is the short name for the Model class being generated
17 connect_info arguments are the same as what DBIx::Class::Schema::connect
18 expects, and are storage_type-specific. For DBI-based storage, these
19 arguments are the dsn, username, password, and connect options,
20 respectively.
21
22=head1 TYPICAL EXAMPLE
23
24 script/myapp_create.pl model Foo DBIC::SchemaLoader dbi:mysql:foodb myuname mypass '{ AutoCommit => 1 }'
7b39f3f0 25
26=head1 DESCRIPTION
27
1aeb6e1e 28This helper generates two classes:
29
30First, it generates a L<DBIx::Class::Schema::Loader> class at
31F<lib/MyApp/SchemaLoader/Foo.pm> based on your supplied dsn/user/pass.
32
33Then, it generates a L<Catalyst::Model::DBIC::Schema> at
34F<lib/MyApp/M/Foo.pm>, which references the above-generated loader.
7b39f3f0 35
36Models generated by this Helper require the seperate package
37L<DBIx::Class::Schema::Loader> to be installed. It is on the recommended
38list for this package, but is not required for installation.
39
40=head2 METHODS
41
42=head3 mk_compclass
43
44=cut
45
46sub mk_compclass {
0b2a7108 47 my ($self, $helper, @connect_info) = @_;
48
49 for(@connect_info) {
50 $_ = qq{'$_'} if $_ !~ /^\s*[[{]/;
51 }
7b39f3f0 52
1aeb6e1e 53 $helper->{loader_class} = $helper->{class};
54 $helper->{loader_class} =~ s/\:\:M(?:odel)?\:\:/::SchemaLoader::/;
55 my @loader_parts = split(/\:\:/, $helper->{loader_class});
56 my $loader_file_part = pop @loader_parts;
57
58 my $loader_dir = File::Spec->catfile( $helper->{base}, 'lib', @loader_parts );
59 my $loader_file = File::Spec->catfile( $loader_dir, $loader_file_part . '.pm' );
60
61 $helper->mk_dir($loader_dir);
0b2a7108 62 $helper->{connect_info} = \@connect_info;
7b39f3f0 63
1aeb6e1e 64 $helper->mk_dir( $loader_dir );
65 $helper->render_file( 'loaderclass', $loader_file );
66
67
7b39f3f0 68 my $file = $helper->{file};
69 $helper->render_file( 'compclass', $file );
70}
71
72=head1 SEE ALSO
73
74General Catalyst Stuff:
75
76L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
77L<Catalyst::Response>, L<Catalyst::Helper>, L<Catalyst>,
78
79Stuff related to DBIC and this Model style:
80
81L<DBIx::Class>, L<DBIx::Class::Schema>,
1aeb6e1e 82L<DBIx::Class::Schema::Loader>, L<Catalyst::Model::DBIC::Schema>,
83L<Catalyst::Helper::Model::DBIC::Schema>
7b39f3f0 84
85=head1 AUTHOR
86
87Brandon L Black, C<blblack@gmail.com>
88
89=head1 LICENSE
90
91This library is free software, you can redistribute it and/or modify
92it under the same terms as Perl itself.
93
94=cut
95
961;
97
98__DATA__
99
5d11d759 100=begin pod_to_ignore
101
1aeb6e1e 102__loaderclass__
103package [% loader_class %];
7b39f3f0 104
105use strict;
106use base qw/DBIx::Class::Schema::Loader/;
107
108__PACKAGE__->load_from_connection(
0b2a7108 109 connect_info => [
110 [% FOREACH arg = connect_info %][% arg %],
111 [% END %]
112 ],
7b39f3f0 113 relationships => 1,
114 # debug => 1,
115);
116
1aeb6e1e 117=head1 NAME
118
119[% loader_class %] - Loader-generated DBIx::Class::Schema class
120
121=head1 SYNOPSIS
122
123See L<[% app %]>
124
125=head1 DESCRIPTION
126
127Generated by L<Catalyst::Model::DBIC::Schema> for use in L<[% class %]>
128
129=head1 AUTHOR
130
131[% author %]
132
133=head1 LICENSE
134
135This library is free software, you can redistribute it and/or modify
136it under the same terms as Perl itself.
137
138=cut
139
1401;
141
142__compclass__
7b39f3f0 143package [% class %];
144
145use strict;
146use base 'Catalyst::Model::DBIC::Schema';
147
148__PACKAGE__->config(
1aeb6e1e 149 schema_class => '[% loader_class %]',
7b39f3f0 150);
151
152=head1 NAME
153
1aeb6e1e 154[% class %] - Catalyst DBIC Schema Model
7b39f3f0 155
156=head1 SYNOPSIS
157
158See L<[% app %]>
159
160=head1 DESCRIPTION
161
1aeb6e1e 162L<Catalyst::Model::DBIC::Schema> Model using L<DBIx::Class::Schema::Loader>
163generated Schema: L<[% loader_class %]>
7b39f3f0 164
165=head1 AUTHOR
166
167[% author %]
168
169=head1 LICENSE
170
171This library is free software, you can redistribute it and/or modify
172it under the same terms as Perl itself.
173
174=cut
175
1761;
5d11d759 177