X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader.pm;h=af3b9bc3d3a9a134d1abe2867a9d841ca6ec056f;hb=refs%2Fheads%2Floader-roles;hp=9d67414483fd0d0e980b724ee018b42a5dac6e53;hpb=7ba9582abe39fb8ffc961c2ddd2bf3df8dc263f4;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/lib/DBIx/Class/Schema/Loader.pm b/lib/DBIx/Class/Schema/Loader.pm index 9d67414..af3b9bc 100644 --- a/lib/DBIx/Class/Schema/Loader.pm +++ b/lib/DBIx/Class/Schema/Loader.pm @@ -16,7 +16,7 @@ use namespace::clean; # Always remember to do all digits for the version even if they're 0 # i.e. first release of 0.XX *must* be 0.XX000. This avoids fBSD ports # brain damage and presumably various other packaging systems too -our $VERSION = '0.07047'; +our $VERSION = '0.07048'; __PACKAGE__->mk_group_accessors('inherited', qw/ _loader_args @@ -24,6 +24,7 @@ __PACKAGE__->mk_group_accessors('inherited', qw/ _loader_invoked _loader loader_class + loader_roles naming use_namespaces /); @@ -187,13 +188,13 @@ sub _invoke_loader { $args->{naming} = $self->naming if $self->naming; $args->{use_namespaces} = $self->use_namespaces if defined $self->use_namespaces; - # XXX this only works for relative storage_type, like ::DBI ... my $loader_class = $self->loader_class; if ($loader_class) { $loader_class = "DBIx::Class::Schema::Loader${loader_class}" if $loader_class =~ /^::/; $args->{loader_class} = $loader_class; }; + # XXX this only works for relative storage_type, like ::DBI ... my $impl = $loader_class || "DBIx::Class::Schema::Loader" . $self->storage_type; try { $self->ensure_class_loaded($impl) @@ -202,7 +203,13 @@ sub _invoke_loader { croak qq/Could not load loader_class "$impl": "$_"/; }; - $class->loader($impl->new(%$args)); + my $loader = $impl->new(%$args); + if (my @roles = @{$self->loader_roles || []}) { + require Role::Tiny; + Role::Tiny->apply_roles_to_object($loader, @roles); + } + + $class->loader($loader); $class->loader->load; $class->_loader_invoked(1); @@ -294,10 +301,10 @@ sub _copy_state_from { See L for basic usage. -If the final argument is a hashref, and it contains the keys C -or C, those keys will be deleted, and their values value will be -used for the loader options or class, respectively, just as if set via the -L or L methods above. +If the final argument is a hashref, and it contains the keys C, +C or C, those keys will be deleted, and their values +value will be used for the loader options or class, respectively, just as if set +via the L or L methods above. The actual auto-loading operation (the heart of this module) will be invoked as soon as the connection information is defined. @@ -309,7 +316,7 @@ sub connection { my $class = ref $self || $self; if($_[-1] && ref $_[-1] eq 'HASH') { - for my $option (qw/loader_class loader_options/) { + for my $option (qw/loader_class loader_options loader_roles/) { if(my $value = delete $_[-1]->{$option}) { $self->$option($value); }