Replicated - fixup types and namespace::clean
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Replicated / Replicant.pm
1 package DBIx::Class::Storage::DBI::Replicated::Replicant;
2
3 use Moose::Role;
4 requires qw/_query_start/;
5 use MooseX::Types::Moose qw/Bool/;
6
7 use namespace::clean -except => 'meta';
8
9 =head1 NAME
10
11 DBIx::Class::Storage::DBI::Replicated::Replicant - A replicated DBI Storage Role
12
13 =head1 SYNOPSIS
14
15 This class is used internally by L<DBIx::Class::Storage::DBI::Replicated>.
16     
17 =head1 DESCRIPTION
18
19 Replicants are DBI Storages that follow a master DBI Storage.  Typically this
20 is accomplished via an external replication system.  Please see the documents
21 for L<DBIx::Class::Storage::DBI::Replicated> for more details.
22
23 This class exists to define methods of a DBI Storage that only make sense when
24 it's a classic 'slave' in a pool of slave databases which replicate from a
25 given master database.
26
27 =head1 ATTRIBUTES
28
29 This class defines the following attributes.
30
31 =head2 active
32
33 This is a boolean which allows you to programmatically activate or deactivate a
34 replicant from the pool.  This way to you do stuff like disallow a replicant
35 when it get's too far behind the master, if it stops replicating, etc.
36
37 This attribute DOES NOT reflect a replicant's internal status, i.e. if it is
38 properly replicating from a master and has not fallen too many seconds behind a
39 reliability threshold.  For that, use L</is_replicating>  and L</lag_behind_master>.
40 Since the implementation of those functions database specific (and not all DBIC
41 supported DB's support replication) you should refer your database specific
42 storage driver for more information.
43
44 =cut
45
46 has 'active' => (
47   is=>'rw',
48   isa=>Bool,
49   lazy=>1,
50   required=>1,
51   default=>1,
52 );
53
54 =head1 METHODS
55
56 This class defines the following methods.
57
58 =head2 around: _query_start
59
60 advice iof the _query_start method to add more debuggin
61
62 =cut
63
64 around '_query_start' => sub {
65   my ($method, $self, $sql, @bind) = @_;
66   my $dsn = $self->_dbi_connect_info->[0];
67   $self->$method("DSN: $dsn SQL: $sql", @bind);
68 };
69
70 =head2 debugobj
71
72 Override the debugobj method to redirect this method call back to the master.
73
74 =cut
75
76 sub debugobj {
77     return shift->schema->storage->debugobj;
78 }
79
80 =head1 ALSO SEE
81
82 L<<a href="http://en.wikipedia.org/wiki/Replicant">http://en.wikipedia.org/wiki/Replicant</a>>
83
84 =head1 AUTHOR
85
86 John Napiorkowski <john.napiorkowski@takkle.com>
87
88 =head1 LICENSE
89
90 You may distribute this code under the same terms as Perl itself.
91
92 =cut
93
94 1;