1 package DBIx::Class::Schema;
6 use base qw/Class::Data::Inheritable/;
9 __PACKAGE__->mk_classdata('_class_registrations' => {});
13 DBIx::Class::Schema - composable schemas
21 use base qw/DBIx::Class::Schema/;
23 __PACKAGE__->load_classes(qw/Foo Bar Baz/);
27 package My::Schema::Foo;
29 use base qw/DBIx::Class::Core/;
31 __PACKAGE__->table('foo');
38 My::Schema->compose_connection('My::DB', $dsn, $user, $pass, $attrs);
42 my @obj = My::DB::Foo->retrieve_all; # My::DB::Foo isa My::Schema::Foo My::DB
53 my ($class, $name, $to_register) = @_;
54 my %reg = %{$class->_class_registrations};
55 $reg{$name} = $to_register;
56 $class->_class_registrations(\%reg);
61 my @comp = grep { $_ !~ /^#/ } @_;
62 foreach my $comp (@comp) {
63 my $comp_class = "${class}::${comp}";
64 eval "use $comp_class";
66 $class->register_class($comp => $comp_class);
70 sub compose_connection {
71 my ($class, $target, @info) = @_;
72 $class->setup_connection_class($target, @info);
73 my %reg = %{ $class->_class_registrations };
74 while (my ($comp, $comp_class) = each %reg) {
75 my $target_class = "${target}::${comp}";
76 $class->inject_base($target_class, $comp_class, $target);
80 sub setup_connection_class {
81 my ($class, $target, @info) = @_;
82 $class->inject_base($target => 'DBIx::Class');
83 $target->load_components('DB');
84 $target->connection(@info);
88 my ($class, $target, @to_inject) = @_;
91 unshift(@{"${target}::ISA"}, @to_inject);
101 Matt S. Trout <perl-stuff@trout.me.uk>
105 You may distribute this code under the same terms as Perl itself.