release 0.06, fixed pod_to_ignore stuff, added an optional half-decent helper test
[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
1aeb6e1e 13 script/myapp_create.pl model Foo DBIC::SchemaLoader dsn user password
7b39f3f0 14
15 Where:
16 Foo is the short name for the Model class being generated
17 dsn, user, and password are the connection info
18
19=head1 DESCRIPTION
20
1aeb6e1e 21This helper generates two classes:
22
23First, it generates a L<DBIx::Class::Schema::Loader> class at
24F<lib/MyApp/SchemaLoader/Foo.pm> based on your supplied dsn/user/pass.
25
26Then, it generates a L<Catalyst::Model::DBIC::Schema> at
27F<lib/MyApp/M/Foo.pm>, which references the above-generated loader.
7b39f3f0 28
29Models generated by this Helper require the seperate package
30L<DBIx::Class::Schema::Loader> to be installed. It is on the recommended
31list for this package, but is not required for installation.
32
33=head2 METHODS
34
35=head3 mk_compclass
36
37=cut
38
39sub mk_compclass {
40 my ( $self, $helper, $dsn, $user, $pass ) = @_;
41
1aeb6e1e 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;
46
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' );
49
50 $helper->mk_dir($loader_dir);
51
7b39f3f0 52 $helper->{dsn} = $dsn || '';
53 $helper->{user} = $user || '';
54 $helper->{pass} = $pass || '';
55
1aeb6e1e 56 $helper->mk_dir( $loader_dir );
57 $helper->render_file( 'loaderclass', $loader_file );
58
59
7b39f3f0 60 my $file = $helper->{file};
61 $helper->render_file( 'compclass', $file );
62}
63
64=head1 SEE ALSO
65
66General Catalyst Stuff:
67
68L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
69L<Catalyst::Response>, L<Catalyst::Helper>, L<Catalyst>,
70
71Stuff related to DBIC and this Model style:
72
73L<DBIx::Class>, L<DBIx::Class::Schema>,
1aeb6e1e 74L<DBIx::Class::Schema::Loader>, L<Catalyst::Model::DBIC::Schema>,
75L<Catalyst::Helper::Model::DBIC::Schema>
7b39f3f0 76
77=head1 AUTHOR
78
79Brandon L Black, C<blblack@gmail.com>
80
81=head1 LICENSE
82
83This library is free software, you can redistribute it and/or modify
84it under the same terms as Perl itself.
85
86=cut
87
881;
89
90__DATA__
91
5d11d759 92=begin pod_to_ignore
93
1aeb6e1e 94__loaderclass__
95package [% loader_class %];
7b39f3f0 96
97use strict;
98use base qw/DBIx::Class::Schema::Loader/;
99
100__PACKAGE__->load_from_connection(
101 dsn => '[% dsn %]',
102 user => '[% user %]',
103 pass => '[% pass %]',
104 options => {
105 RaiseError => 1,
106 PrintError => 0,
107 ShowErrorStatement => 1,
108 TraceLevel => 0,
109 AutoCommit => 1,
110 },
111 relationships => 1,
112 # debug => 1,
113);
114
1aeb6e1e 115=head1 NAME
116
117[% loader_class %] - Loader-generated DBIx::Class::Schema class
118
119=head1 SYNOPSIS
120
121See L<[% app %]>
122
123=head1 DESCRIPTION
124
125Generated by L<Catalyst::Model::DBIC::Schema> for use in L<[% class %]>
126
127=head1 AUTHOR
128
129[% author %]
130
131=head1 LICENSE
132
133This library is free software, you can redistribute it and/or modify
134it under the same terms as Perl itself.
135
136=cut
137
1381;
139
140__compclass__
7b39f3f0 141package [% class %];
142
143use strict;
144use base 'Catalyst::Model::DBIC::Schema';
145
146__PACKAGE__->config(
1aeb6e1e 147 schema_class => '[% loader_class %]',
7b39f3f0 148);
149
150=head1 NAME
151
1aeb6e1e 152[% class %] - Catalyst DBIC Schema Model
7b39f3f0 153
154=head1 SYNOPSIS
155
156See L<[% app %]>
157
158=head1 DESCRIPTION
159
1aeb6e1e 160L<Catalyst::Model::DBIC::Schema> Model using L<DBIx::Class::Schema::Loader>
161generated Schema: L<[% loader_class %]>
7b39f3f0 162
163=head1 AUTHOR
164
165[% author %]
166
167=head1 LICENSE
168
169This library is free software, you can redistribute it and/or modify
170it under the same terms as Perl itself.
171
172=cut
173
1741;
5d11d759 175