Commit | Line | Data |
1aeb6e1e |
1 | package Catalyst::Helper::Model::DBIC::SchemaLoader; |
7b39f3f0 |
2 | |
3 | use strict; |
4 | use warnings; |
5 | use Carp; |
6 | |
7 | =head1 NAME |
8 | |
1aeb6e1e |
9 | Catalyst::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 |
21 | This helper generates two classes: |
22 | |
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. |
25 | |
26 | Then, it generates a L<Catalyst::Model::DBIC::Schema> at |
27 | F<lib/MyApp/M/Foo.pm>, which references the above-generated loader. |
7b39f3f0 |
28 | |
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. |
32 | |
33 | =head2 METHODS |
34 | |
35 | =head3 mk_compclass |
36 | |
37 | =cut |
38 | |
39 | sub 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 | |
66 | General Catalyst Stuff: |
67 | |
68 | L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>, |
69 | L<Catalyst::Response>, L<Catalyst::Helper>, L<Catalyst>, |
70 | |
71 | Stuff related to DBIC and this Model style: |
72 | |
73 | L<DBIx::Class>, L<DBIx::Class::Schema>, |
1aeb6e1e |
74 | L<DBIx::Class::Schema::Loader>, L<Catalyst::Model::DBIC::Schema>, |
75 | L<Catalyst::Helper::Model::DBIC::Schema> |
7b39f3f0 |
76 | |
77 | =head1 AUTHOR |
78 | |
79 | Brandon L Black, C<blblack@gmail.com> |
80 | |
81 | =head1 LICENSE |
82 | |
83 | This library is free software, you can redistribute it and/or modify |
84 | it under the same terms as Perl itself. |
85 | |
86 | =cut |
87 | |
88 | 1; |
89 | |
251bf02f |
90 | =begin pod_to_ignore |
91 | |
7b39f3f0 |
92 | __DATA__ |
93 | |
1aeb6e1e |
94 | __loaderclass__ |
95 | package [% loader_class %]; |
7b39f3f0 |
96 | |
97 | use strict; |
98 | use 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 | |
121 | See L<[% app %]> |
122 | |
123 | =head1 DESCRIPTION |
124 | |
125 | Generated by L<Catalyst::Model::DBIC::Schema> for use in L<[% class %]> |
126 | |
127 | =head1 AUTHOR |
128 | |
129 | [% author %] |
130 | |
131 | =head1 LICENSE |
132 | |
133 | This library is free software, you can redistribute it and/or modify |
134 | it under the same terms as Perl itself. |
135 | |
136 | =cut |
137 | |
138 | 1; |
139 | |
140 | __compclass__ |
7b39f3f0 |
141 | package [% class %]; |
142 | |
143 | use strict; |
144 | use 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 | |
156 | See L<[% app %]> |
157 | |
158 | =head1 DESCRIPTION |
159 | |
1aeb6e1e |
160 | L<Catalyst::Model::DBIC::Schema> Model using L<DBIx::Class::Schema::Loader> |
161 | generated Schema: L<[% loader_class %]> |
7b39f3f0 |
162 | |
163 | =head1 AUTHOR |
164 | |
165 | [% author %] |
166 | |
167 | =head1 LICENSE |
168 | |
169 | This library is free software, you can redistribute it and/or modify |
170 | it under the same terms as Perl itself. |
171 | |
172 | =cut |
173 | |
174 | 1; |