made connect_info optional in the case that the underlying schema already has connect...
[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 [ dsn user password ]
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       dsn, user, and password are optional if connection info is already
20         defined in your Schema class (as it would be in the case of
21         DBIx::Class::Schema::Loader).
22
23 =head1 DESCRIPTION
24
25 Helper for the DBIC Plain Models.
26
27 =head2 METHODS
28
29 =head3 mk_compclass
30
31 =cut
32
33 sub mk_compclass {
34     my ( $self, $helper, $schema_class, $dsn, $user, $pass ) = @_;
35
36     $helper->{schema_class} = $schema_class || '';
37
38     if(defined($dsn)) {
39         $helper->{setup_connect_info} = 1;
40         $helper->{dsn}         = $dsn  || '';
41         $helper->{user}        = $user || '';
42         $helper->{pass}        = $pass || '';
43     }
44
45     my $file = $helper->{file};
46     $helper->render_file( 'compclass', $file );
47 }
48
49 =head1 SEE ALSO
50
51 L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
52 L<Catalyst::Response>, L<Catalyst::Helper>
53
54 =head1 AUTHOR
55
56 Brandon L Black, C<blblack@gmail.com>
57
58 =head1 LICENSE
59
60 This library is free software, you can redistribute it and/or modify
61 it under the same terms as Perl itself.
62
63 =cut
64
65 1;
66
67 __DATA__
68
69 __compclass__
70 package [% class %];
71
72 use strict;
73 use base 'Catalyst::Model::DBIC::Schema';
74
75 __PACKAGE__->config(
76     schema_class => '[% schema_class %]',
77     [% IF setup_connect_info %]
78     connect_info => [ '[% dsn %]',
79                       '[% user %]',
80                       '[% pass %]',
81                       {
82                           RaiseError         => 1,
83                           PrintError         => 0,
84                           ShowErrorStatement => 1,
85                           TraceLevel         => 0,
86                           AutoCommit         => 1,
87                       }
88                     ],
89     [% END %]
90 );
91
92 =head1 NAME
93
94 [% class %] - Catalyst DBIC Plain Model
95
96 =head1 SYNOPSIS
97
98 See L<[% app %]>
99
100 =head1 DESCRIPTION
101
102 Catalyst::Model::DBIC::Schema Model
103
104 =head1 AUTHOR
105
106 [% author %]
107
108 =head1 LICENSE
109
110 This library is free software, you can redistribute it and/or modify
111 it under the same terms as Perl itself.
112
113 =cut
114
115 1;