use Moose;
no warnings 'uninitialized';
-our $VERSION = '0.25';
+our $VERSION = '0.32';
+$VERSION = eval $VERSION;
use Carp;
use Tie::IxHash ();
use List::Util 'first';
use MooseX::Types::Moose qw/Str HashRef Bool ArrayRef/;
use Catalyst::Model::DBIC::Schema::Types 'CreateOption';
-use Moose::Autobox;
use List::MoreUtils 'firstidx';
use Scalar::Util 'looks_like_number';
exclude='^(wibble|wobble)$' moniker_map='{ foo => "FOO" }' \
dbi:Pg:dbname=foodb myuname mypass
+Coderefs are also supported:
+
+ script/myapp_create.pl model CatalystModelName DBIC::Schema \
+ MyApp::SchemaClass create=static \
+ inflect_singular='sub { $_[0] =~ /\A(.+?)(_id)?\z/; $1 }' \
+ moniker_map='sub { join(q{}, map ucfirst, split(/[\W_]+/, lc $_[0])); }' \
+ dbi:mysql:foodb myuname mypass
+
See L<DBIx::Class::Schema::Loader::Base> for a list of options
Create a dynamic DBIx::Class::Schema::Loader-based Schema,
sub BUILD {
my $self = shift;
my $helper = $self->helper;
- my @args = $self->args->flatten if $self->args;
+ my @args = @{ $self->args || [] };
$helper->{schema_class} = $self->schema_class;
$self->traits(\@traits);
$helper->{traits} = '['
- .(join ',' => map { qq{'$_'} } ($self->traits->flatten))
+ .(join ',' => map { qq{'$_'} } @traits)
.']';
splice @args, $traits_idx, 1, ();
$self->_parse_loader_args(\@args);
$helper->{loader_args} = $self->_build_helper_loader_args;
+ }
+ }
- if (first { /^dbi:/i } @args) {
- $helper->{setup_connect_info} = 1;
+ my $dbi_dsn_part;
+ if (first { ($dbi_dsn_part) = /^(dbi):/i } @args) {
+ die
+qq{DSN must start with 'dbi:' not '$dbi_dsn_part' (case matters!)}
+ if $dbi_dsn_part ne 'dbi';
- $helper->{connect_info} =
- $self->_build_helper_connect_info(\@args);
+ $helper->{setup_connect_info} = 1;
- $self->_parse_connect_info(\@args);
- }
- }
+ $helper->{connect_info} =
+ $self->_build_helper_connect_info(\@args);
+
+ $self->_parse_connect_info(\@args);
}
$helper->{generator} = ref $self;
my %loader_args;
- while (@$args && $args->[0] !~ /^dbi:/) {
+ while (@$args && $args->[0] !~ /^dbi:/i) {
my ($key, $val) = split /=/, shift(@$args), 2;
if ($self->_is_struct($val)) {
sub _is_struct {
my ($self, $val) = @_;
- return $val =~ /^\s*[[{]/;
+ return $val =~ /^\s*(?:sub|[[{])/;
}
sub _quote {
=head1 AUTHOR
-Brandon L Black, C<blblack@gmail.com>
+See L<Catalyst::Model::DBIC::Schema/AUTHOR> and
+L<Catalyst::Model::DBIC::Schema/CONTRIBUTORS>.
-Contributors:
+=head1 COPYRIGHT
-Rafael Kitover, C<rkitover at cpan.org>
+See L<Catalyst::Model::DBIC::Schema/COPYRIGHT>.
=head1 LICENSE