release for 0.07, ->require and connect_info args stuff
[catagits/Catalyst-Model-DBIC-Schema.git] / lib / Catalyst / Helper / Model / DBIC / Schema.pm
1 package Catalyst::Helper::Model::DBIC::Schema;
2
3 use strict;
4 use warnings;
5 use Carp;
6
7 =head1 NAME
8
9 Catalyst::Helper::Model::DBIC::Schema - Helper for DBIC Schema Models
10
11 =head1 SYNOPSIS
12
13   script/create.pl model Foo DBIC::Schema Foo::SchemaClass [ connect_info arguments ]
14
15   Where:
16     Foo is the short name for the Model class being generated
17     Foo::SchemaClass is the fully qualified classname of your Schema,
18       which isa DBIx::Class::Schema defined elsewhere.
19     connect_info arguments are the same as what DBIx::Class::Schema::connect
20       expects, and are storage_type-specific.  For DBI-based storage, these
21       arguments are the dsn, username, password, and connect options,
22       respectively.
23
24 =head1 TYPICAL EXAMPLES
25
26   script/myapp_create.pl model Foo DBIC::Schema FooSchema dbi:mysql:foodb myuname mypass '{ AutoCommit => 1 }'
27
28   # -or, if the schema already has connection info and you want to re-use that:
29   script/myapp_create.pl model Foo DBIC::Schema FooSchema
30
31 =head1 DESCRIPTION
32
33 Helper for the DBIC Schema Models.
34
35 =head2 METHODS
36
37 =head3 mk_compclass
38
39 =cut
40
41 sub mk_compclass {
42     my ( $self, $helper, $schema_class, @connect_info) = @_;
43
44     $helper->{schema_class} = $schema_class || '';
45
46     if(@connect_info) {
47         $helper->{setup_connect_info} = 1;
48         for(@connect_info) {
49             $_ = qq{'$_'} if $_ !~ /^\s*[[{]/;
50         }
51         $helper->{connect_info} = \@connect_info;
52     }
53
54     my $file = $helper->{file};
55     $helper->render_file( 'compclass', $file );
56 }
57
58 =head1 SEE ALSO
59
60 General Catalyst Stuff:
61
62 L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
63 L<Catalyst::Response>, L<Catalyst::Helper>, L<Catalyst>,
64
65 Stuff related to DBIC and this Model style:
66
67 L<DBIx::Class>, L<DBIx::Class::Schema>,
68 L<DBIx::Class::Schema::Loader>, L<Catalyst::Model::DBIC::Schema>,
69 L<Catalyst::Helper::Model::DBIC::SchemaLoader>
70
71 =head1 AUTHOR
72
73 Brandon L Black, C<blblack@gmail.com>
74
75 =head1 LICENSE
76
77 This library is free software, you can redistribute it and/or modify
78 it under the same terms as Perl itself.
79
80 =cut
81
82 1;
83
84 __DATA__
85
86 =begin pod_to_ignore
87
88 __compclass__
89 package [% class %];
90
91 use strict;
92 use base 'Catalyst::Model::DBIC::Schema';
93
94 __PACKAGE__->config(
95     schema_class => '[% schema_class %]',
96     [% IF setup_connect_info %]connect_info => [
97         [% FOREACH arg = connect_info %][% arg %],
98         [% END %]
99     ],[% END %]
100 );
101
102 =head1 NAME
103
104 [% class %] - Catalyst DBIC Schema Model
105
106 =head1 SYNOPSIS
107
108 See L<[% app %]>
109
110 =head1 DESCRIPTION
111
112 L<Catalyst::Model::DBIC::Schema> Model using schema
113 L<[% schema_class %]>
114
115 =head1 AUTHOR
116
117 [% author %]
118
119 =head1 LICENSE
120
121 This library is free software, you can redistribute it and/or modify
122 it under the same terms as Perl itself.
123
124 =cut
125
126 1;