X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema.pm;h=47fb8637400e673609d99f3f5b836e7eb7dd9ebb;hb=4190ff95124ad2b3f33067b2e7d6ccfb919dab7c;hp=fbfd15bff0166c1d0c8fed22d8805416cccab547;hpb=87bf71d54c0e5bd50700d8e3be59b79e9b670012;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index fbfd15b..47fb863 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -7,11 +7,8 @@ use DBIx::Class::Exception; use Carp::Clan qw/^DBIx::Class|^Try::Tiny/; use Try::Tiny; use Scalar::Util 'weaken'; -use File::Spec; use Sub::Name 'subname'; -use Module::Find(); -use Storable(); -use B qw/svref_2object/; +use B 'svref_2object'; use namespace::clean; use base qw/DBIx::Class/; @@ -79,20 +76,32 @@ particular which module inherits off which. __PACKAGE__->load_namespaces(); __PACKAGE__->load_namespaces( - result_namespace => 'Res', - resultset_namespace => 'RSet', - default_resultset_class => '+MyDB::Othernamespace::RSet', - ); + result_namespace => 'Res', + resultset_namespace => 'RSet', + default_resultset_class => '+MyDB::Othernamespace::RSet', + ); + +With no arguments, this method uses L to load all of the +Result and ResultSet classes under the namespace of the schema from +which it is called. For example, C will by default find +and load Result classes named C and ResultSet +classes named C. + +ResultSet classes are associated with Result class of the same name. +For example, C will get the ResultSet class +C if it is present. + +Both Result and ResultSet namespaces are configurable via the +C and C options. + +Another option, C specifies a custom default +ResultSet class for Result classes with no corresponding ResultSet. -With no arguments, this method uses L to load all your -Result classes from a sub-namespace F under your Schema class' -namespace, i.e. with a Schema of I all files in -I are assumed to be Result classes. +All of the namespace and classname options are by default relative to +the schema classname. To specify a fully-qualified name, prefix it +with a literal C<+>. For example, C<+Other::NameSpace::Result>. -It also finds all ResultSet classes in the namespace F and -loads them into the appropriate Result classes using for you. The -matching is done by assuming the package name of the ResultSet class -is the same as that of the Result class. +=head3 Warnings You will be warned if ResultSet classes are discovered for which there are no matching Result classes like this: @@ -105,19 +114,7 @@ L to some other class, you will be warned like this: We found ResultSet class '$rs_class' for '$result', but it seems that you had already set '$result' to use '$rs_set' instead -Both of the sub-namespaces are configurable if you don't like the defaults, -via the options C and C. - -If (and only if) you specify the option C, any found -Result classes for which we do not find a corresponding -ResultSet class will have their C set to -C. - -All of the namespace and classname options to this method are relative to -the schema classname by default. To specify a fully-qualified name, prefix -it with a literal C<+>. - -Examples: +=head3 Examples # load My::Schema::Result::CD, My::Schema::Result::Artist, # My::Schema::ResultSet::CD, etc... @@ -139,10 +136,10 @@ Examples: resultset_namespace => '+Another::Place::RSets', ); -If you'd like to use multiple namespaces of each type, simply use an arrayref -of namespaces for that option. In the case that the same result -(or resultset) class exists in multiple namespaces, the latter entries in -your list of namespaces will override earlier ones. +To search multiple namespaces for either Result or ResultSet classes, +use an arrayref of namespaces for that option. In the case that the +same result (or resultset) class exists in multiple namespaces, later +entries in the list of namespaces will override earlier ones. My::Schema->load_namespaces( # My::Schema::Results_C::Foo takes precedence over My::Schema::Results_B::Foo : @@ -169,6 +166,7 @@ sub _findallmod { my $proto = shift; my $ns = shift || ref $proto || $proto; + require Module::Find; my @mods = Module::Find::findallmod($ns); # try to untaint module names. mods where this fails @@ -1189,6 +1187,8 @@ format. sub ddl_filename { my ($self, $type, $version, $dir, $preversion) = @_; + require File::Spec; + my $filename = ref($self); $filename =~ s/::/-/g; $filename = File::Spec->catfile($dir, "$filename-$version-$type.sql"); @@ -1208,6 +1208,7 @@ reference to any schema, so are rather useless. sub thaw { my ($self, $obj) = @_; local $DBIx::Class::ResultSourceHandle::thaw_schema = $self; + require Storable; return Storable::thaw($obj); } @@ -1219,6 +1220,7 @@ provided here for symmetry. =cut sub freeze { + require Storable; return Storable::nfreeze($_[1]); } @@ -1241,6 +1243,7 @@ objects so their references to the schema object sub dclone { my ($self, $obj) = @_; local $DBIx::Class::ResultSourceHandle::thaw_schema = $self; + require Storable; return Storable::dclone($obj); }