Algorithm-VectorClocks
view release on metacpan or search on metacpan
lib/Algorithm/VectorClocks.pm view on Meta::CPAN
__PACKAGE__->mk_classdata($_) for qw(id json);
__PACKAGE__->id(hostname);
__PACKAGE__->json(JSON::Any->new);
sub new {
my $class = shift;
my($arg) = @_;
my $self = UNIVERSAL::isa($arg, $class) ? $arg
: { clocks => $class->json->jsonToObj($arg || '{}') };
bless $self, $class;
}
sub serialize {
my $self = shift;
$self->json->objToJson($self->clocks);
}
sub increment {
my $self = shift;
$self->clocks->{ $self->id }++; # increment its own clock
( run in 0.279 second using v1.01-cache-2.11-cpan-de7293f3b23 )