re-worked C::H::M::DBIC::SchemaInlineLoader code into a better C::H::M::DBIC::SchemaL...
[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 Schema 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 General Catalyst Stuff:
52
53 L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
54 L<Catalyst::Response>, L<Catalyst::Helper>, L<Catalyst>,
55
56 Stuff related to DBIC and this Model style:
57
58 L<DBIx::Class>, L<DBIx::Class::Schema>,
59 L<DBIx::Class::Schema::Loader>, L<Catalyst::Model::DBIC::Schema>,
60 L<Catalyst::Helper::Model::DBIC::SchemaLoader>
61
62 =head1 AUTHOR
63
64 Brandon L Black, C<blblack@gmail.com>
65
66 =head1 LICENSE
67
68 This library is free software, you can redistribute it and/or modify
69 it under the same terms as Perl itself.
70
71 =cut
72
73 1;
74
75 __DATA__
76
77 __compclass__
78 package [% class %];
79
80 use strict;
81 use base 'Catalyst::Model::DBIC::Schema';
82
83 __PACKAGE__->config(
84     schema_class => '[% schema_class %]',
85     [% IF setup_connect_info %]
86     connect_info => [ '[% dsn %]',
87                       '[% user %]',
88                       '[% pass %]',
89                       {
90                           RaiseError         => 1,
91                           PrintError         => 0,
92                           ShowErrorStatement => 1,
93                           TraceLevel         => 0,
94                           AutoCommit         => 1,
95                       }
96                     ],
97     [% END %]
98 );
99
100 =head1 NAME
101
102 [% class %] - Catalyst DBIC Schema Model
103
104 =head1 SYNOPSIS
105
106 See L<[% app %]>
107
108 =head1 DESCRIPTION
109
110 L<Catalyst::Model::DBIC::Schema> Model using schema
111 L<[% schema_class %]>
112
113 =head1 AUTHOR
114
115 [% author %]
116
117 =head1 LICENSE
118
119 This library is free software, you can redistribute it and/or modify
120 it under the same terms as Perl itself.
121
122 =cut
123
124 1;