-
Notifications
You must be signed in to change notification settings - Fork 0
/
Event.pm
59 lines (40 loc) · 995 Bytes
/
Event.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package Event;
use strict;
use warnings;
use overload '<=>' => \&three_way_comparison, '""' => \&stringification;
sub new {
my ($class, $type, $timestamp, $payload) = @_;
my $self = {
type => $type,
timestamp => $timestamp,
payload => $payload,
};
bless $self, $class;
return $self;
}
sub type {
my ($self, $type) = @_;
$self->{type} = $type if (defined $type);
return $self->{type};
}
sub timestamp {
my ($self, $timestamp) = @_;
$self->{timestamp} = $timestamp if (defined $timestamp);
return $self->{timestamp};
}
sub payload {
my ($self, $payload) = @_;
$self->{payload} = $payload if (defined $payload);
return $self->{payload};
}
sub three_way_comparison {
my ($self, $other, $inverted) = @_;
return $self->{type} <=> $other->{type} if
($self->{timestamp} == $other->{timestamp});
return $self->{timestamp} <=> $other->{timestamp};
}
sub stringification {
my ($self) = @_;
return "[$self->{type}, $self->{timestamp}, ($self->{payload})]";
}
1;