Revision history for DBIx::Class
+ * New Features / Changes
+ - A bunch of nonsensically named arguments to the SQL::Translator
+ parser have been marked as deprecated (while still fully
+ supported)
+
* Fixes
- Fix duplicated selected columns when calling 'count' when a same
aggregate function is used more than once in a 'having' clause
sub parse {
my ($tr, $data) = @_;
my $args = $tr->parser_args;
- my $dbicschema = $args->{'DBIx::Class::Schema'} || $args->{"DBIx::Schema"} ||$data;
- $dbicschema ||= $args->{'package'};
- my $limit_sources = $args->{'sources'};
+
+ my $dbicschema = $data || $args->{dbic_schema};
+
+ for (qw(DBIx::Class::Schema DBIx::Schema package)) {
+ if (defined (my $s = delete $args->{$_} )) {
+ carp_unique("Supplying a schema via ... parser_args => { '$_' => \$schema } is deprecated. Please use parser_args => { dbic_schema => \$schema } instead");
+
+ # move it from the deprecated to the proper $args slot
+ unless ($dbicschema) {
+ $args->{dbic_schema} = $dbicschema = $s;
+ }
+ }
+ }
DBIx::Class::Exception->throw('No DBIx::Class::Schema') unless ($dbicschema);
+
if (!ref $dbicschema) {
eval "require $dbicschema"
or DBIx::Class::Exception->throw("Can't load $dbicschema: $@");
unless ($schema->name);
my @monikers = sort $dbicschema->sources;
- if ($limit_sources) {
+ if (my $limit_sources = $args->{'sources'}) {
my $ref = ref $limit_sources || '';
$dbicschema->throw_exception ("'sources' parameter must be an array or hash ref")
unless( $ref eq 'ARRAY' || ref eq 'HASH' );
my $trans = SQL::Translator->new (
parser => 'SQL::Translator::Parser::DBIx::Class',
parser_args => {
- package => $schema,
+ dbic_schema => $schema,
add_fk_index => 0,
sources => [qw/
Artist
=head1 PARSER OPTIONS
+=head2 dbic_schema
+
+The DBIx::Class schema (either an instance or a class name) to be parsed.
+This argument is in fact optional - instead one can supply it later at
+translation time as an argument to L<SQL::Translator/translate>. In
+other words both of the following invocations are valid and will produce
+conceptually identical output:
+
+ my $yaml = SQL::Translator->new(
+ parser => 'SQL::Translator::Parser::DBIx::Class',
+ parser_args => {
+ dbic_schema => $schema,
+ },
+ producer => 'SQL::Translator::Producer::YAML',
+ )->translate;
+
+ my $yaml = SQL::Translator->new(
+ parser => 'SQL::Translator::Parser::DBIx::Class',
+ producer => 'SQL::Translator::Producer::YAML',
+ )->translate(data => $schema);
+
=head2 add_fk_index
Create an index for each foreign key.
use warnings;
use Test::More;
+use Test::Warn;
use Test::Exception;
use Scalar::Util ();
my @schemas = (
create_schema ({ schema => $s }),
- create_schema ({ args => { parser_args => { 'DBIx::Class::Schema' => $s } } }),
- create_schema ({ args => { parser_args => { 'DBIx::Schema' => $s } } }),
- create_schema ({ args => { parser_args => { package => $s } } }),
+ create_schema ({ args => { parser_args => { dbic_schema => $s } } }),
);
+ for my $parser_args_key (qw(
+ DBIx::Class::Schema
+ DBIx::Schema
+ package
+ )) {
+ warnings_exist {
+ push @schemas, create_schema({
+ args => { parser_args => { $parser_args_key => $s } }
+ });
+ } qr/\Qparser_args => {\E.+?is deprecated/,
+ "deprecated crazy parser_arg '$parser_args_key' warned";
+ }
+
Scalar::Util::weaken ($s);
ok (!$s, 'Schema not leaked');
sub create_schema {
my $args = shift;
- my $schema = $args->{schema};
my $additional_sqltargs = $args->{args} || {};
my $sqltargs = {
my $sqlt = SQL::Translator->new( $sqltargs );
$sqlt->parser('SQL::Translator::Parser::DBIx::Class');
- return $sqlt->translate({ data => $schema }) || die $sqlt->error;
+ return $sqlt->translate(
+ $args->{schema} ? ( data => $args->{schema} ) : ()
+ ) || die $sqlt->error;
}
sub get_table {