line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!perl |
2
|
|
|
|
|
|
|
# vim: softtabstop=4 tabstop=4 shiftwidth=4 ft=perl expandtab smarttab |
3
|
|
|
|
|
|
|
# PODNAME: RT::Client::REST::Attachment |
4
|
|
|
|
|
|
|
# ABSTRACT: attachment object representation. |
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
89418
|
use strict; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
76
|
|
7
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
125
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$RT::Client::REST::Attachment::VERSION = '0.70'; |
10
|
|
|
|
|
|
|
use parent 'RT::Client::REST::Object'; |
11
|
3
|
|
|
3
|
|
369
|
|
|
3
|
|
|
|
|
240
|
|
|
3
|
|
|
|
|
14
|
|
12
|
|
|
|
|
|
|
use Params::Validate qw(:types); |
13
|
3
|
|
|
3
|
|
187
|
use RT::Client::REST::Object::Exception; |
|
3
|
|
|
|
|
16
|
|
|
3
|
|
|
|
|
437
|
|
14
|
3
|
|
|
3
|
|
20
|
|
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
34
|
|
15
|
|
|
|
|
|
|
id => { |
16
|
|
|
|
|
|
|
validation => { |
17
|
3
|
|
|
3
|
|
77
|
type => SCALAR, |
18
|
|
|
|
|
|
|
regex => qr/^\d+$/, |
19
|
|
|
|
|
|
|
}, |
20
|
|
|
|
|
|
|
}, |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
creator_id => { |
23
|
|
|
|
|
|
|
validation => { |
24
|
|
|
|
|
|
|
type => SCALAR, |
25
|
|
|
|
|
|
|
regex => qr/^\d+$/, |
26
|
|
|
|
|
|
|
}, |
27
|
|
|
|
|
|
|
rest_name => 'Creator', |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
parent_id => { |
31
|
|
|
|
|
|
|
validation => { |
32
|
|
|
|
|
|
|
type => SCALAR, |
33
|
|
|
|
|
|
|
regex => qr/^\d+$/, |
34
|
|
|
|
|
|
|
}, |
35
|
|
|
|
|
|
|
}, |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
subject => { |
38
|
|
|
|
|
|
|
validation => { |
39
|
|
|
|
|
|
|
type => SCALAR, |
40
|
|
|
|
|
|
|
}, |
41
|
|
|
|
|
|
|
}, |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
content_type => { |
44
|
|
|
|
|
|
|
validation => { |
45
|
|
|
|
|
|
|
type => SCALAR, |
46
|
|
|
|
|
|
|
}, |
47
|
|
|
|
|
|
|
rest_name => 'ContentType', |
48
|
|
|
|
|
|
|
}, |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
file_name => { |
51
|
|
|
|
|
|
|
validation => { |
52
|
|
|
|
|
|
|
type => SCALAR, |
53
|
|
|
|
|
|
|
}, |
54
|
|
|
|
|
|
|
rest_name => 'Filename', |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
transaction_id => { |
58
|
|
|
|
|
|
|
validation => { |
59
|
|
|
|
|
|
|
type => SCALAR, |
60
|
|
|
|
|
|
|
regex => qr/^\d+$/, |
61
|
|
|
|
|
|
|
}, |
62
|
|
|
|
|
|
|
rest_name => 'Transaction', |
63
|
|
|
|
|
|
|
}, |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
message_id => { |
66
|
|
|
|
|
|
|
validation => { |
67
|
|
|
|
|
|
|
type => SCALAR, |
68
|
|
|
|
|
|
|
}, |
69
|
|
|
|
|
|
|
rest_name => 'MessageId', |
70
|
|
|
|
|
|
|
}, |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
created => { |
73
|
|
|
|
|
|
|
validation => { |
74
|
|
|
|
|
|
|
type => SCALAR, |
75
|
|
|
|
|
|
|
}, |
76
|
|
|
|
|
|
|
is_datetime => 1, |
77
|
|
|
|
|
|
|
}, |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
content => { |
80
|
|
|
|
|
|
|
validation => { |
81
|
|
|
|
|
|
|
type => SCALAR, |
82
|
|
|
|
|
|
|
}, |
83
|
|
|
|
|
|
|
}, |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
headers => { |
86
|
|
|
|
|
|
|
validation => { |
87
|
|
|
|
|
|
|
type => SCALAR, |
88
|
|
|
|
|
|
|
}, |
89
|
|
|
|
|
|
|
}, |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
parent => { |
92
|
|
|
|
|
|
|
validation => { |
93
|
|
|
|
|
|
|
type => SCALAR, |
94
|
|
|
|
|
|
|
}, |
95
|
|
|
|
|
|
|
}, |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
content_encoding => { |
98
|
|
|
|
|
|
|
validation => { |
99
|
|
|
|
|
|
|
type => SCALAR, |
100
|
|
|
|
|
|
|
}, |
101
|
|
|
|
|
|
|
rest_name => 'ContentEncoding', |
102
|
|
|
|
|
|
|
}, |
103
|
|
|
|
|
|
|
}} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $self = shift; |
107
|
1
|
|
|
1
|
1
|
875
|
|
108
|
|
|
|
|
|
|
$self->from_form( |
109
|
|
|
|
|
|
|
$self->rt->get_attachment( |
110
|
0
|
|
|
0
|
1
|
0
|
parent_id => $self->parent_id, |
111
|
|
|
|
|
|
|
id => $self->id, |
112
|
0
|
|
|
|
|
0
|
), |
113
|
|
|
|
|
|
|
); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
$self->{__dirty} = {}; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
return $self; |
118
|
|
|
|
|
|
|
} |
119
|
0
|
|
|
|
|
0
|
|
120
|
|
|
|
|
|
|
my @unsupported = qw(store search count); |
121
|
0
|
|
|
|
|
0
|
# Override unsupported methods. |
122
|
|
|
|
|
|
|
for my $method (@unsupported) { |
123
|
|
|
|
|
|
|
no strict 'refs'; ## no critic (ProhibitNoStrict) |
124
|
|
|
|
|
|
|
*$method = sub { |
125
|
|
|
|
|
|
|
my $self = shift; |
126
|
|
|
|
|
|
|
RT::Client::REST::Object::IllegalMethodException->throw( |
127
|
3
|
|
|
3
|
|
1042
|
ref($self) . " does not support '$method' method", |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
453
|
|
128
|
|
|
|
|
|
|
); |
129
|
6
|
|
|
6
|
|
4981
|
}; |
130
|
6
|
|
|
|
|
40
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# FIXME this is kind of horrible, probably functions should be provided via mixin? |
133
|
|
|
|
|
|
|
my ($self, $method) = @_; |
134
|
|
|
|
|
|
|
if (grep { $_ eq $method } @unsupported) { |
135
|
|
|
|
|
|
|
return; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
return $self->SUPER::can($method); |
138
|
17
|
|
|
17
|
1
|
4907
|
} |
139
|
17
|
50
|
|
|
|
24
|
|
|
51
|
|
|
|
|
108
|
|
140
|
0
|
|
|
|
|
0
|
__PACKAGE__->_generate_methods; |
141
|
|
|
|
|
|
|
|
142
|
17
|
|
|
|
|
89
|
1; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=pod |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=encoding UTF-8 |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 NAME |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
RT::Client::REST::Attachment - attachment object representation. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 VERSION |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
version 0.70 |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 SYNOPSIS |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
my $attachments = $ticket->attachments; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
my $count = $attachments->count; |
162
|
|
|
|
|
|
|
print "There are $count attachments.\n"; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
my $iterator = $attachments->get_iterator; |
165
|
|
|
|
|
|
|
while (my $att = &$iterator) { |
166
|
|
|
|
|
|
|
print "Id: ", $att->id, "; Subject: ", $att->subject, "\n"; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 DESCRIPTION |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
An attachment is a second-class citizen, as it does not exist (at least |
172
|
|
|
|
|
|
|
from the current REST protocol implementation) by itself. At the moment, |
173
|
|
|
|
|
|
|
it is always associated with a ticket (see B<parent_id> attribute). |
174
|
|
|
|
|
|
|
Thus, you will |
175
|
|
|
|
|
|
|
rarely retrieve an attachment by itself; instead, you should use |
176
|
|
|
|
|
|
|
C<attachments()> method of L<RT::Client::REST::Ticket> object to get |
177
|
|
|
|
|
|
|
an iterator for all attachments for that ticket. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=over 2 |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item B<id> |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Numeric ID of the attachment. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item B<creator_id> |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Numeric ID of the user who created the attachment. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item B<parent_id> |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Numeric ID of the object the attachment is associated with. This is not |
194
|
|
|
|
|
|
|
a proper attribute of the attachment as specified by REST -- it is simply |
195
|
|
|
|
|
|
|
to store the ID of the L<RT::Client::REST::Ticket> object this attachment |
196
|
|
|
|
|
|
|
belongs to. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item B<subject> |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Subject of the attachment. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=item B<content_type> |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Content type. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=item B<file_name> |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
File name (if any). |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=item B<transaction_id> |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Numeric ID of the L<RT::Client::REST::Transaction> object this attachment |
213
|
|
|
|
|
|
|
is associated with. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=item B<message_id> |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Message ID. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=item B<created> |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Time when the attachment was created |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item B<content> |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Actual content of the attachment. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=item B<headers> |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Headers (not parsed), if any. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=item B<parent> |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Parent (not sure what this is yet). |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=item B<content_encoding> |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
Content encoding, if any. |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=back |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head1 METHODS |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
B<RT::Client::REST::Attachment> is a read-only object, so you cannot |
244
|
|
|
|
|
|
|
C<store()> it. Also, because it is a second-class citizen, you cannot |
245
|
|
|
|
|
|
|
C<search()> or C<count()> it -- use C<attachments()> method provided |
246
|
|
|
|
|
|
|
by L<RT::Client::REST::Ticket>. |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=over 2 |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=item retrieve |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
To retrieve an attachment, attributes B<id> and B<parent_id> must |
253
|
|
|
|
|
|
|
be set. |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=back |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=head1 INTERNAL METHODS |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=over 2 |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=item B<can> |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
Wraps the normal I<can()> call, to exclude unsupported methods from parent. |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=item B<rt_type> |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
Returns 'attachment'. |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=back |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=head1 CREATING ATTACHMENTS |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
Currently RT does not allow creating attachments via their API. |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
See L<https://rt-wiki.bestpractical.com/wiki/REST#Ticket_Attachment> |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=head1 SEE ALSO |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
L<RT::Client::REST::Ticket>, |
280
|
|
|
|
|
|
|
L<RT::Client::REST::SearchResult>. |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=head1 AUTHOR |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
Dean Hamstead <dean@fragfest.com.au> |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
This software is copyright (c) 2022, 2020 by Dmitri Tikhonov. |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
291
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=cut |