[Dbix-class] PATCH: load_classes_except()
Christopher H. Laco
claco at chrislaco.com
Fri Jul 21 19:15:23 CEST 2006
Drew Taylor wrote:
> Ok, this is a VERY VERY simple patch and doesn't cover nearly the
> functionality that load_classes() has, but it works for me in my
> simple test. It should have unit tests and support namespaces like
> it's counterpart, but you have to start somewhere. :-)
>
> Drew
>
> <BEGIN PATCH>
>
> =head2 load_classes_except
>
> =over 4
>
> =item Arguments: @classes?
>
> =back
>
> This method loads all classes except for those you specify
> (using L<use>), and registers them (using L</"register_class">).
> It is very similar to L</"load_classes"> in that it allows
> you to load all but a select few classes automatically.
>
> Example:
>
> # Given classes: My::Schema::CD, My::Schema::Artist, My::Schema::Track
>
> # loads ::Artist and ::Track but not ::CD
> My::Schema->load_classes_except('CD');
>
> =cut
>
> sub load_classes_except {
> my ($class, @excluded) = @_;
> eval "require Module::Find;";
> $class->throw_exception(
> "No arguments to load_classes and couldn't load Module::Find ($@)"
> ) if $@;
> my @all_comps = map { substr $_, length "${class}::" }
> Module::Find::findallmod($class);
> my %excluded = map { substr $_, length "${class}::" => undef } @excluded;
> my @comp;
> foreach my $to_check (@all_comps) {
> push(@comp, $to_check) unless exists $excluded{$to_check};
> }
> # lazy me!
> $class->load_classes(@comp);
> }
> <END PATCH>
>
If I were a betting man, I'd much rather see some ducktyping and a
callback from within load_classes.
That way, my Schema subclass can do anything it wants when a class is
found and about to be loaded; including ignoring it.
-=Chris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: OpenPGP digital signature
Url : http://lists.rawmode.org/pipermail/dbix-class/attachments/20060721/d9414b7a/attachment.pgp
More information about the Dbix-class
mailing list