File Coverage

blib/lib/Algorithm/Paxos/Role/Learner.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Algorithm::Paxos::Role::Learner;
2             {
3             $Algorithm::Paxos::Role::Learner::VERSION = '0.001';
4             }
5 1     1   3658 use Moose::Role;
  0            
  0            
6             use namespace::autoclean;
7              
8             # ABSTRACT: A Learner role for the Paxos algorithm
9              
10             has proposals => (
11             isa => 'HashRef',
12             traits => ['Hash'],
13             default => sub { +{} },
14             handles => {
15             learn => 'set',
16             proposal_ids => 'keys',
17             proposal_count => 'count',
18             proposal => 'get',
19             }
20             );
21              
22             sub latest_proposal {
23             my $self = shift;
24             my ($last) = reverse sort $self->proposal_ids;
25             return unless $last;
26             $self->get_proposal($last);
27             }
28              
29             1;
30              
31              
32             =pod
33              
34             =head1 NAME
35              
36             Algorithm::Paxos::Role::Learner - A Learner role for the Paxos algorithm
37              
38             =head1 VERSION
39              
40             version 0.001
41              
42             =head1 SYNOPSIS
43              
44             package MyApp::PaxosBasic;
45             use Moose;
46            
47             with qw(Algorithm::Paxos::Role::Learner);
48            
49             1;
50             __END__
51              
52             =head1 DESCRIPTION
53              
54             From L<Wikipedia|http://en.wikipedia.org/wiki/Paxos_algorithm>
55              
56             Learners act as the replication factor for the protocol. Once a Client
57             request has been agreed on by the Acceptors, the Learner may take action
58             (i.e.: execute the request and send a response to the client). To improve
59             availability of processing, additional Learners can be added.
60              
61             =head1 METHODS
62              
63             =head2 learn ( $id, $value )
64              
65             This is the main interface between Acceptors and Leaners. When a value is
66             choosen by the cluster, C<learn> is passed the id and value and is recorded in
67             stable storage. The default implementation stores everything in an in-memory
68             HashRef.
69              
70             =head2 proposal_ids ( ) : @ids
71              
72             Returns a list of proposal ids.
73              
74             =head2 proposal_count ( ) : $count
75              
76             Returns the number of proposals to date.
77              
78             =head2 latest_proposal ( ) : $value
79              
80             Returns the value of the proposal with the greatest id.
81              
82             =meethod proposal ( $id ) : $value
83              
84             Returns the value stored for C<$id>.
85              
86             =head1 AUTHOR
87              
88             Chris Prather <chris@prather.org>
89              
90             =head1 COPYRIGHT AND LICENSE
91              
92             This software is copyright (c) 2012 by Chris Prather.
93              
94             This is free software; you can redistribute it and/or modify it under
95             the same terms as the Perl 5 programming language system itself.
96              
97             =cut
98              
99              
100             __END__
101