| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package EventStore::Tiny::Event; |
|
2
|
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
58250
|
use strict; |
|
|
8
|
|
|
|
|
27
|
|
|
|
8
|
|
|
|
|
235
|
|
|
4
|
8
|
|
|
8
|
|
33
|
use warnings; |
|
|
8
|
|
|
|
|
18
|
|
|
|
8
|
|
|
|
|
183
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
3861
|
use UUID::Tiny qw(create_uuid_as_string); |
|
|
8
|
|
|
|
|
151511
|
|
|
|
8
|
|
|
|
|
535
|
|
|
7
|
8
|
|
|
8
|
|
57
|
use Time::HiRes qw(time); |
|
|
8
|
|
|
|
|
25
|
|
|
|
8
|
|
|
|
|
45
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Class::Tiny { |
|
10
|
2
|
|
|
|
|
45
|
uuid => sub {create_uuid_as_string}, |
|
11
|
298
|
|
|
|
|
1549
|
timestamp => sub {time}, |
|
12
|
1
|
|
|
|
|
9
|
name => sub {die "name is required.\n"}, |
|
13
|
1
|
|
|
|
|
35
|
transformation => sub {sub {}}, |
|
14
|
8
|
|
|
8
|
|
2526
|
}; |
|
|
8
|
|
|
|
|
3006
|
|
|
|
8
|
|
|
|
|
241
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub BUILD { |
|
17
|
299
|
|
|
299
|
0
|
67230
|
my $self = shift; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Set non-lazy |
|
20
|
299
|
|
|
|
|
4569
|
$self->name; |
|
21
|
298
|
|
|
|
|
4582
|
$self->timestamp; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Return nothing (will be ignored anyway) |
|
24
|
298
|
|
|
|
|
510
|
return; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Lets transformation work on state by side-effect |
|
28
|
|
|
|
|
|
|
sub apply_to { |
|
29
|
31
|
|
|
31
|
1
|
6194
|
my ($self, $state, $logger) = @_; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Apply the transformation by side effect |
|
32
|
31
|
|
|
|
|
411
|
$self->transformation->($state); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Log this event, if logger present |
|
35
|
31
|
100
|
|
|
|
199
|
$logger->($self) if defined $logger; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Returned the same state just in case |
|
38
|
31
|
|
|
|
|
103
|
return $state; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Return a one-line summary of this event |
|
42
|
|
|
|
|
|
|
sub summary { |
|
43
|
15
|
|
|
15
|
1
|
22
|
my $self = shift; |
|
44
|
15
|
50
|
|
|
|
201
|
my $decimals = $self->timestamp =~ /(\.\d+)$/ ? $1 : ''; |
|
45
|
15
|
|
|
|
|
334
|
my @time_parts = localtime $self->timestamp; |
|
46
|
15
|
|
|
|
|
635
|
return sprintf '[%s (%4d-%02d-%02dT%02d:%02d:%02d%s)]', |
|
47
|
|
|
|
|
|
|
$self->name, |
|
48
|
|
|
|
|
|
|
$time_parts[5] + 1900, # Year |
|
49
|
|
|
|
|
|
|
@time_parts[4, 3, 2, 1, 0], # Rest of time representation |
|
50
|
|
|
|
|
|
|
$decimals; # Possibly empty |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=pod |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=encoding utf-8 |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 NAME |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
EventStore::Tiny::Event |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 REFERENCE |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
EventStore::Tiny::Event implements the following attributes and methods. |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 ATTRIBUTES |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
All these attributes can be manipulated by setters/getters with the attribute's name or can be set on construction: |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $event = EventStore::Tiny::Event->new(name => "Foo"); |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head3 uuid |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
This event's UUID. By default a new UUID is created. |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head3 timestamp |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This event's timestamp. By default a new timestamp of the creation time is set. |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head3 name |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This event's name. Setting this attribute on construction is required. |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head3 transformation |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This event's state transformation function, represented by a subref. By default it does nothing, so it should be set as a reasonable subref changing the given state argument (as a hashref) based on the given data (as a hashref) by side-effect. |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 METHODS |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head3 apply_to |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$event->apply_to(\%state, $logger); |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Applies this event's L to the given state (by side-effect). If a C<$logger> as a subref is given, it is used to log this application. |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head3 summary |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
say $event->summary; |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Returns a one-line summarized stringification of this event. |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
L |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Copyright (c) 2018 Mirko Westermeier (mail: mirko@westermeier.de) |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Released under the MIT License (see LICENSE.txt for details). |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |