Commit | Line | Data |
26ab719a |
1 | package DBIx::Class::Storage::DBI::Replicated::Replicant; |
2 | |
0bbe6676 |
3 | use Moo::Role; |
4 | use DBIx::Class::Storage::DBI::Replicated::Types |
5 | qw(Boolean DBICStorageDBI Defined); |
6 | |
edbf2778 |
7 | requires qw/_query_start/; |
ee356d00 |
8 | with 'DBIx::Class::Storage::DBI::Replicated::WithDSN'; |
26ab719a |
9 | |
10 | =head1 NAME |
11 | |
21fc4719 |
12 | DBIx::Class::Storage::DBI::Replicated::Replicant - A replicated DBI Storage Role |
26ab719a |
13 | |
14 | =head1 SYNOPSIS |
15 | |
de5dc9ef |
16 | This class is used internally by L<DBIx::Class::Storage::DBI::Replicated>. |
d4daee7b |
17 | |
26ab719a |
18 | =head1 DESCRIPTION |
19 | |
20 | Replicants are DBI Storages that follow a master DBI Storage. Typically this |
21 | is accomplished via an external replication system. Please see the documents |
22 | for L<DBIx::Class::Storage::DBI::Replicated> for more details. |
23 | |
24 | This class exists to define methods of a DBI Storage that only make sense when |
25 | it's a classic 'slave' in a pool of slave databases which replicate from a |
26 | given master database. |
27 | |
28 | =head1 ATTRIBUTES |
29 | |
30 | This class defines the following attributes. |
31 | |
50336325 |
32 | =head2 active |
33 | |
34 | This is a boolean which allows you to programmatically activate or deactivate a |
48580715 |
35 | replicant from the pool. This way you can do stuff like disallow a replicant |
36 | when it gets too far behind the master, if it stops replicating, etc. |
50336325 |
37 | |
9c748388 |
38 | This attribute DOES NOT reflect a replicant's internal status, i.e. if it is |
39 | properly replicating from a master and has not fallen too many seconds behind a |
40 | reliability threshold. For that, use L</is_replicating> and L</lag_behind_master>. |
41 | Since the implementation of those functions database specific (and not all DBIC |
48580715 |
42 | supported DBs support replication) you should refer your database-specific |
9c748388 |
43 | storage driver for more information. |
44 | |
50336325 |
45 | =cut |
46 | |
47 | has 'active' => ( |
64cdad22 |
48 | is=>'rw', |
0bbe6676 |
49 | isa=>Boolean, |
64cdad22 |
50 | lazy=>1, |
51 | required=>1, |
0bbe6676 |
52 | default=> sub {1}, |
50336325 |
53 | ); |
54 | |
0bbe6676 |
55 | has dsn => (is => 'rw', isa => Defined(err=>sub{"'dsn' must be defined"})); |
56 | has id => (is => 'rw', isa => Defined(err=>sub{"'id' must be defined"})); |
0bd8e058 |
57 | |
cea43436 |
58 | =head2 master |
59 | |
60 | Reference to the master Storage. |
61 | |
62 | =cut |
63 | |
0bbe6676 |
64 | has master => ( |
65 | is => 'rw', |
66 | isa =>DBICStorageDBI, |
67 | weak_ref => 1, |
68 | ); |
cea43436 |
69 | |
26ab719a |
70 | =head1 METHODS |
71 | |
72 | This class defines the following methods. |
73 | |
edbf2778 |
74 | =head2 debugobj |
75 | |
76 | Override the debugobj method to redirect this method call back to the master. |
77 | |
78 | =cut |
79 | |
80 | sub debugobj { |
0bbe6676 |
81 | (shift)->master->debugobj; |
edbf2778 |
82 | } |
83 | |
e515254d |
84 | =head1 ALSO SEE |
85 | |
ee356d00 |
86 | L<http://en.wikipedia.org/wiki/Replicant>, |
87 | L<DBIx::Class::Storage::DBI::Replicated> |
e515254d |
88 | |
26ab719a |
89 | =head1 AUTHOR |
90 | |
0bbe6676 |
91 | John Napiorkowski <jjnapiork@cpan.org> |
26ab719a |
92 | |
93 | =head1 LICENSE |
94 | |
95 | You may distribute this code under the same terms as Perl itself. |
96 | |
50336325 |
97 | =cut |
98 | |
41916570 |
99 | 1; |