Commit | Line | Data |
26ab719a |
1 | package DBIx::Class::Storage::DBI::Replicated::Replicant; |
2 | |
de5dc9ef |
3 | use Moose::Role; |
edbf2778 |
4 | requires qw/_query_start/; |
41916570 |
5 | use MooseX::Types::Moose qw/Bool/; |
6 | |
7 | use namespace::clean -except => 'meta'; |
26ab719a |
8 | |
9 | =head1 NAME |
10 | |
21fc4719 |
11 | DBIx::Class::Storage::DBI::Replicated::Replicant - A replicated DBI Storage Role |
26ab719a |
12 | |
13 | =head1 SYNOPSIS |
14 | |
de5dc9ef |
15 | This class is used internally by L<DBIx::Class::Storage::DBI::Replicated>. |
26ab719a |
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 | |
50336325 |
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 | |
9c748388 |
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 | |
50336325 |
44 | =cut |
45 | |
46 | has 'active' => ( |
64cdad22 |
47 | is=>'rw', |
41916570 |
48 | isa=>Bool, |
64cdad22 |
49 | lazy=>1, |
50 | required=>1, |
51 | default=>1, |
50336325 |
52 | ); |
53 | |
26ab719a |
54 | =head1 METHODS |
55 | |
56 | This class defines the following methods. |
57 | |
f15afa13 |
58 | =head2 around: _query_start |
50336325 |
59 | |
60 | advice iof the _query_start method to add more debuggin |
61 | |
62 | =cut |
63 | |
64 | around '_query_start' => sub { |
64cdad22 |
65 | my ($method, $self, $sql, @bind) = @_; |
16df8aa9 |
66 | my $dsn = $self->_dbi_connect_info->[0]; |
64cdad22 |
67 | $self->$method("DSN: $dsn SQL: $sql", @bind); |
50336325 |
68 | }; |
69 | |
edbf2778 |
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 | |
e515254d |
80 | =head1 ALSO SEE |
81 | |
82 | L<<a href="http://en.wikipedia.org/wiki/Replicant">http://en.wikipedia.org/wiki/Replicant</a>> |
83 | |
26ab719a |
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 | |
50336325 |
92 | =cut |
93 | |
41916570 |
94 | 1; |