line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Argon::Message; |
2
|
|
|
|
|
|
|
# ABSTRACT: Encodable message structure used for cross-system coordination |
3
|
|
|
|
|
|
|
$Argon::Message::VERSION = '0.18'; |
4
|
|
|
|
|
|
|
|
5
|
7
|
|
|
7
|
|
2386
|
use strict; |
|
7
|
|
|
|
|
22
|
|
|
7
|
|
|
|
|
245
|
|
6
|
7
|
|
|
7
|
|
54
|
use warnings; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
247
|
|
7
|
7
|
|
|
7
|
|
127
|
use Carp; |
|
7
|
|
|
|
|
41
|
|
|
7
|
|
|
|
|
494
|
|
8
|
7
|
|
|
7
|
|
1347
|
use Moose; |
|
7
|
|
|
|
|
1661602
|
|
|
7
|
|
|
|
|
66
|
|
9
|
7
|
|
|
7
|
|
65047
|
use Data::UUID; |
|
7
|
|
|
|
|
4615
|
|
|
7
|
|
|
|
|
498
|
|
10
|
7
|
|
|
7
|
|
472
|
use Argon::Constants qw(:priorities :commands); |
|
7
|
|
|
|
|
20
|
|
|
7
|
|
|
|
|
1551
|
|
11
|
7
|
|
|
7
|
|
2436
|
use Argon::Types; |
|
7
|
|
|
|
|
27
|
|
|
7
|
|
|
|
|
305
|
|
12
|
7
|
|
|
7
|
|
1406
|
use Argon::Util qw(param); |
|
7
|
|
|
|
|
28
|
|
|
7
|
|
|
|
|
3757
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has id => ( |
16
|
|
|
|
|
|
|
is => 'ro', |
17
|
|
|
|
|
|
|
isa => 'Str', |
18
|
|
|
|
|
|
|
default => sub { Data::UUID->new->create_str }, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has cmd => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
isa => 'Ar::Command', |
25
|
|
|
|
|
|
|
required => 1, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has pri => ( |
30
|
|
|
|
|
|
|
is => 'ro', |
31
|
|
|
|
|
|
|
isa => 'Ar::Priority', |
32
|
|
|
|
|
|
|
default => $NORMAL, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has info => ( |
37
|
|
|
|
|
|
|
is => 'ro', |
38
|
|
|
|
|
|
|
isa => 'Any', |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has token => ( |
43
|
|
|
|
|
|
|
is => 'rw', |
44
|
|
|
|
|
|
|
isa => 'Maybe[Str]', |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
5
|
|
|
5
|
1
|
223
|
sub failed { $_[0]->cmd eq $ERROR } |
49
|
6
|
|
|
6
|
1
|
247
|
sub denied { $_[0]->cmd eq $DENY } |
50
|
0
|
|
|
0
|
1
|
0
|
sub copy { $_[0]->reply(id => Data::UUID->new->create_str) } |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub reply { |
54
|
8
|
|
|
8
|
1
|
62
|
my ($self, %param) = @_; |
55
|
8
|
|
|
|
|
375
|
Argon::Message->new( |
56
|
|
|
|
|
|
|
%$self, # copy $self |
57
|
|
|
|
|
|
|
token => undef, # remove token (unless in %param) |
58
|
|
|
|
|
|
|
%param, # add caller's parameters |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub error { |
64
|
1
|
|
|
1
|
1
|
6
|
my ($self, $error, %param) = @_; |
65
|
1
|
|
|
|
|
9
|
$self->reply(%param, cmd => $ERROR, info => $error); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub result { |
70
|
3
|
|
|
3
|
1
|
81
|
my $self = shift; |
71
|
3
|
50
|
|
|
|
15
|
return $self->failed ? croak($self->info) |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
72
|
|
|
|
|
|
|
: $self->denied ? croak($self->info) |
73
|
|
|
|
|
|
|
: $self->cmd eq $ACK ? 1 |
74
|
|
|
|
|
|
|
: $self->info; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub explain { |
79
|
30
|
|
|
30
|
1
|
78
|
my $self = shift; |
80
|
30
|
|
100
|
|
|
1701
|
sprintf '[P%d %5s %s %s]', $self->pri, $self->cmd, $self->token || '-', $self->id; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
__END__ |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=pod |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=encoding UTF-8 |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 NAME |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Argon::Message - Encodable message structure used for cross-system coordination |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 VERSION |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
version 0.18 |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 SYNOPSIS |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
use Argon::Message; |
104
|
|
|
|
|
|
|
use Argon ':commands', ':priorities'; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $msg = Argon::Message->new( |
107
|
|
|
|
|
|
|
cmd => $PING, |
108
|
|
|
|
|
|
|
pri => $NORMAL, |
109
|
|
|
|
|
|
|
info => {thing => ['with', 'data', 'in', 'it']}, |
110
|
|
|
|
|
|
|
); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my $reply = $msg->reply(info => '...'); |
113
|
|
|
|
|
|
|
my $error = $msg->error("some error message"); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 DESCRIPTION |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Argon protocol messages. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 id |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Unique identifier for the conversation. Used to track the course of a task from |
124
|
|
|
|
|
|
|
the client to the manager to the worker and back. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 cmd |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
The command verb. See L<Argon::Constants/:commands>. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 pri |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
The message priority. See L<Argon::Constants/:priorities>. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 info |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
The data payload of the message. May be a string, reference, et al. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 token |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Used internally by L<Argon::SecureChannel> to identify message senders. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 METHODS |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 failed |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Returns true if the C<cmd> is C<$ERROR>. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 denied |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Returns true if the C<cmd> is C<$DENY>. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 copy |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Returns a shallow copy of the message with a new id and token. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 reply |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Returns a copy of the message. Any additional parameters passed are passed |
159
|
|
|
|
|
|
|
transparently to C<new>. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 error |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Returns a new message with the same id, C<cmd> set to C<$ERROR>, and C<info> |
164
|
|
|
|
|
|
|
set to the supplied error message. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 result |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Returns the decoded data playload. If the message is an C<$ERROR> or C<$DENY>, |
169
|
|
|
|
|
|
|
croaks with C<info> as the error message. If the message is an C<$ACK>, returns |
170
|
|
|
|
|
|
|
true. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 explain |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Returns a formatted string describing the message. Useful for debugging and |
175
|
|
|
|
|
|
|
logging. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 AUTHOR |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Jeff Ober <sysread@fastmail.fm> |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Jeff Ober. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
186
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |