From: Dagfinn Ilmari Mannsåker Date: Tue, 20 Feb 2018 10:21:38 +0000 (+0000) Subject: Add loader_roles option X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Floader-roles;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Add loader_roles option TODO: Optional::Dependencies, docs, tests --- diff --git a/lib/DBIx/Class/Schema/Loader.pm b/lib/DBIx/Class/Schema/Loader.pm index 05d951f..af3b9bc 100644 --- a/lib/DBIx/Class/Schema/Loader.pm +++ b/lib/DBIx/Class/Schema/Loader.pm @@ -24,6 +24,7 @@ __PACKAGE__->mk_group_accessors('inherited', qw/ _loader_invoked _loader loader_class + loader_roles naming use_namespaces /); @@ -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); }