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>

-- 
----------------------------------------------------------------
 Drew Taylor                 *  Web development & consulting
 Email: [EMAIL PROTECTED]  *  Site implementation & hosting
 Web  : www.drewtaylor.com   *  perl/mod_perl/DBI/mysql/postgres
 ----------------------------------------------------------------

_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/

Reply via email to