X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema.pm;h=2451f55720e1eb71b7578588a84eafbd29bdd672;hb=5d9c76e106f9ac8929bf1dddeeb157bed8d404ac;hp=4b945cc7aeb9c546ce5deecc1cf4c5bb1e56eab3;hpb=109765190925eacd136c768c02c8fac580e4aadd;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index 4b945cc..2451f55 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -8,7 +8,7 @@ use Carp::Clan qw/^DBIx::Class/; use Scalar::Util qw/weaken/; use File::Spec; use Sub::Name (); -require Module::Find; +use Module::Find(); use base qw/DBIx::Class/; @@ -42,7 +42,7 @@ DBIx::Class::Schema - composable schemas $dsn, $user, $password, - { AutoCommit => 0 }, + { AutoCommit => 1 }, ); my $schema2 = Library::Schema->connect($coderef_returning_dbh); @@ -239,16 +239,29 @@ sub load_namespaces { local *Class::C3::reinitialize = sub { }; use warnings 'redefine'; - # ensure classes are loaded and fetch properly sorted classes + # ensure classes are loaded and attached in inheritance order $class->ensure_class_loaded($_) foreach(values %results); - my @subclass_last = sort { $results{$a}->isa($results{$b}) } keys(%results); - + my %inh_idx; + my @subclass_last = sort { + + ($inh_idx{$a} ||= + scalar @{mro::get_linear_isa( $results{$a} )} + ) + + <=> + + ($inh_idx{$b} ||= + scalar @{mro::get_linear_isa( $results{$b} )} + ) + + } keys(%results); + foreach my $result (@subclass_last) { my $result_class = $results{$result}; my $rs_class = delete $resultsets{$result}; my $rs_set = $class->_ns_get_rsrc_instance ($result_class)->resultset_class; - + if($rs_set && $rs_set ne 'DBIx::Class::ResultSet') { if($rs_class && $rs_class ne $rs_set) { carp "We found ResultSet class '$rs_class' for '$result', but it seems " @@ -285,8 +298,10 @@ sub load_namespaces { =back -Alternative method to L which you should look at -using if you can. +L is an alternative method to L, both of +which serve similar purposes, each with different advantages and disadvantages. +In the general case you should use L, unless you need to +be able to specify that only specific classes are loaded at runtime. With no arguments, this method uses L to find all classes under the schema's namespace. Otherwise, this method loads the classes you specify @@ -496,7 +511,7 @@ syntax on the C<@connectinfo> argument, or L in general. Note that C expects an arrayref of arguments, but -C does not. C wraps it's arguments in an arrayref +C does not. C wraps its arguments in an arrayref before passing them to C. =head3 Overloading @@ -528,6 +543,8 @@ name. sub resultset { my ($self, $moniker) = @_; + $self->throw_exception('resultset() expects a source name') + unless defined $moniker; return $self->source($moniker)->resultset; } @@ -740,7 +757,7 @@ i.e., [ 2, 'Indie Band' ], ... ]); - + Since wantarray context is basically the same as looping over $rs->create(...) you won't see any performance benefits and in this case the method is more for convenience. Void context sends the column information directly to storage @@ -791,13 +808,13 @@ Overload C to change the behaviour of C. sub connection { my ($self, @info) = @_; return $self if !@info && $self->storage; - + my ($storage_class, $args) = ref $self->storage_type ? ($self->_normalize_storage_type($self->storage_type),{}) : ($self->storage_type, {}); - + $storage_class = 'DBIx::Class::Storage'.$storage_class if $storage_class =~ m/^::/; - eval "require ${storage_class};"; + eval { $self->ensure_class_loaded ($storage_class) }; $self->throw_exception( "No arguments to load_classes and couldn't load ${storage_class} ($@)" ) if $@; @@ -1109,6 +1126,19 @@ name format is: C<$dir$schema-$version-$type.sql>. You may override this method in your schema if you wish to use a different format. + WARNING + + Prior to DBIx::Class version 0.08100 this method had a different signature: + + my $filename = $table->ddl_filename($type, $dir, $version, $preversion) + + In recent versions variables $dir and $version were reversed in order to + bring the signature in line with other Schema/Storage methods. If you + really need to maintain backward compatibility, you can do the following + in any overriding methods: + + ($dir, $version) = ($version, $dir) if ($DBIx::Class::VERSION < 0.08100); + =cut sub ddl_filename { @@ -1118,7 +1148,7 @@ sub ddl_filename { $filename =~ s/::/-/g; $filename = File::Spec->catfile($dir, "$filename-$version-$type.sql"); $filename =~ s/$version/$preversion-$version/ if($preversion); - + return $filename; } @@ -1344,7 +1374,7 @@ more information. $self->throw_exception ("No arguments to load_classes and couldn't load ${base} ($@)") if $@; - + if ($self eq $target) { # Pathological case, largely caused by the docs on early C::M::DBIC::Plain foreach my $moniker ($self->sources) { @@ -1357,14 +1387,14 @@ more information. $self->connection(@info); return $self; } - + my $schema = $self->compose_namespace($target, $base); { no strict 'refs'; my $name = join '::', $target, 'schema'; *$name = Sub::Name::subname $name, sub { $schema }; } - + $schema->connection(@info); foreach my $moniker ($schema->sources) { my $source = $schema->source($moniker);