package Catalyst::Helper::Model::DBIC::SchemaInlineLoader;

use strict;
use warnings;
use Carp;

=head1 NAME

Catalyst::Helper::Model::DBIC::SchemaInlineLoader - Helper for AutoLoaded DBIC Schema Models

=head1 SYNOPSIS

    script/create.pl model Foo DBIC::SchemaInlineLoader dsn user password

    Where:
      Foo is the short name for the Model class being generated
      dsn, user, and password are the connection info

=head1 DESCRIPTION

This helper generates a Catalyst::Model::DBIC::Schema class based upon a
generated inline DBIx::Class::Schema::Loader definition.  Nothing external
to the generated class is required.

Models generated by this Helper require the seperate package
L<DBIx::Class::Schema::Loader> to be installed.  It is on the recommended
list for this package, but is not required for installation.

=head2 METHODS

=head3 mk_compclass

=cut

sub mk_compclass {
    my ( $self, $helper, $dsn, $user, $pass ) = @_;

    $helper->{dsn}          = $dsn  || '';
    $helper->{user}         = $user || '';
    $helper->{pass}         = $pass || '';

    my $file = $helper->{file};
    $helper->render_file( 'compclass', $file );
}

=head1 SEE ALSO

General Catalyst Stuff:

L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
L<Catalyst::Response>, L<Catalyst::Helper>, L<Catalyst>,

Stuff related to DBIC and this Model style:

L<DBIx::Class>, L<DBIx::Class::Schema>,
L<DBIx::Class::Schema::Loader>, L<Catalyst::Helper::Model::DBIC::Schema>,
L<Catalyst::Helper::Model::DBIC::SchemaInlineLoader>

=head1 AUTHOR

Brandon L Black, C<blblack@gmail.com>

=head1 LICENSE

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;

__DATA__

__compclass__
package [% %]_[% class %]::Schema;

use strict;
use base qw/DBIx::Class::Schema::Loader/;

__PACKAGE__->load_from_connection(
    dsn     => '[% dsn %]',
    user    => '[% user %]',
    pass    => '[% pass %]',
    options => {
                  RaiseError         => 1,
                  PrintError         => 0,
                  ShowErrorStatement => 1,
                  TraceLevel         => 0,
                  AutoCommit         => 1,
                },
    relationships => 1,
    # debug => 1,
);

package [% class %];

use strict;
use base 'Catalyst::Model::DBIC::Schema';

__PACKAGE__->config(
    schema_class => '_[% class %]::Schema',
);

=head1 NAME

[% class %] - Catalyst DBIC Plain Model

=head1 SYNOPSIS

See L<[% app %]>

=head1 DESCRIPTION

Catalyst::Model::DBIC::Schema Model

=head1 AUTHOR

[% author %]

=head1 LICENSE

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;
