C::M::DBIC::Schema - warn on create=dynamic, other cleanups, ::Role::Replicated ...
[catagits/Catalyst-Model-DBIC-Schema.git] / lib / Catalyst / Model / DBIC / Schema / Role / Replicated.pm
CommitLineData
c4fee9b8 1package Catalyst::Model::DBIC::Schema::Role::Replicated;
2
3use Moose::Role;
4use Moose::Autobox;
5use Carp::Clan '^Catalyst::Model::DBIC::Schema';
6
7use Catalyst::Model::DBIC::Schema::Types 'ConnectInfos';
8
9use namespace::clean -except => 'meta';
10
11=head1 NAME
12
13Catalyst::Model::DBIC::Schema::Role::Replicated - Replicated storage support for
14L<Catalyst::Model::DBIC::Schema>
15
16=head1 SYNOPSiS
17
18 __PACKAGE__->config({
19 roles => ['Replicated']
20 connect_info =>
21 ['dbi:mysql:master', 'user', 'pass'],
22 replicants => [
23 ['dbi:mysql:slave1', 'user', 'pass'],
24 ['dbi:mysql:slave2', 'user', 'pass'],
25 ['dbi:mysql:slave3', 'user', 'pass'],
26 ]
27 });
28
29=head1 DESCRIPTION
30
31B<DOES NOT WORK YET> -- requires some DBIC changes
32
33Sets your storage_type to L<DBIx::Class::Storage::DBI::Replicated> and connects
34replicants provided in config. See that module for supported resultset
35attributes.
36
37=head1 CONFIG PARAMETERS
38
39=head2 replicants
40
41Array of connect_info settings for every replicant.
42
43=cut
44
45has replicants => (
46 is => 'ro', isa => ConnectInfos, coerce => 1, required => 1
47);
48
49after setup => sub {
50 my $self = shift;
51
52# check storage_type compatibility (if configured)
53 if (my $storage_type = $self->storage_type) {
54 my $class = $storage_type =~ /^::/ ?
55 "DBIx::Class::Storage$storage_type"
56 : $storage_type;
57
58 croak "This storage_type cannot be used with replication"
59 unless $class->isa('DBIx::Class::Storage::DBI::Replicated');
60 } else {
61 $self->storage_type('::DBI::Replicated');
62 }
63};
64
65after finalize => sub {
66 my $self = shift;
67
68 $self->storage->connect_replicants($self->replicants->flatten);
69};
70
71=head1 SEE ALSO
72
73L<Catalyst::Model::DBIC::Schema>, L<DBIx::Class>,
74L<DBIx::Class::Storage::DBI::Replicated>,
75L<Cache::FastMmap>, L<DBIx::Class::Cursor::Cached>
76
77=head1 AUTHOR
78
79Rafael Kitover, C<rkitover@cpan.org>
80
81=head1 COPYRIGHT
82
83This program is free software, you can redistribute it and/or modify it
84under the same terms as Perl itself.
85
86=cut
87
881;