Lyskom/AuxItem.pm

filter: Statementstmt 46.4% 58 / 125 Branchbran 16.1% 11 / 68 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 55.0% 11 / 20 Podpod 93.3% 14 / 15 totaltotal 41.2% 94 / 228 CC 36 SCAR 35.4
CC
36
Cov
36%
new
132.0
to_server
42.0
tag
12.0
CRAP 34.4
« Lyskom.pm ↑ Summary Lyskom/Simple.pm »
1 package Net::Lyskom::AuxItem;
2 1 ▶use base qw{Net::Lyskom::Object};
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Net::Lyskom::Util qw{:all};
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Net::Lyskom::AuxItem - Object representing a Protocol A AuxItem.
12  
13 =head1 SYNOPSIS
14  
15 $ai = Net::Lyskom::AuxItem->new(
16 tag => "content_type",
17 data => "text/html"
18 );
19  
20 =head1 DESCRIPTION
21  
22 A helper module for Net::Lyskom
23  
24 =head2 Methods
25  
26 =over
27  
28 =cut
29  
30 1 our %type = (
31 content_type => 1,
32 fast_reply => 2,
33 cross_reference => 3,
34 no_comments => 4,
35 personal_comment => 5,
36 request_confirmation => 6,
37 read_confirm => 7,
38 redirect => 8,
39 x_face => 9,
40 alternate_name => 10,
41 pgp_signature => 11,
42 pgp_public_key => 12,
43 e_mail_address => 13,
44 faq_text => 14,
45 creating_software => 15,
46 mx_author => 16,
47 mx_from => 17,
48 mx_reply_to => 18,
49 mx_to => 19,
50 mx_cc => 20,
51 mx_date => 21,
52 mx_message_id => 22,
53 mx_in_reply_to => 23,
54 mx_misc => 24,
55 mx_allow_filter => 25,
56 mx_reject_forward => 26,
57 notify_comments => 27,
58 faq_for_conf => 28,
59 recommended_conf => 29,
60 allowed_content_type => 30,
61 canonical_name => 31,
62 mx_list_name => 32,
63 send_comment_to => 33,
64 mx_mime_belongs_to => 10100,
65 mx_mime_part_in => 10101,
66 mx_mime_misc => 10102,
67 mx_envelope_sender => 10103,
68 mx_mime_file_name => 10104
69 );
70  
71 1 our %epyt = reverse %type;
72  
73 =item new(tag => content_type, [...])
74  
75 Create a new AuxItem object. All possible attributes can be set at
76 creation time, by use of fairly standard arguments. What the attributes
77 are and what they mean can be found in the Protocol A documentation. All
78 names are kept the same, except that hyphens have been changed to underscores.
79  
80 =cut
81  
82 0 ▶sub new {
Subroutine new: not called CC=11 SCAR=48.8
Pod documented
83 0 my $self = {};
84 0 my $class = shift;
85 0 my %a = @_;
86  
87 0 ▶ $class = ref($class) if ref($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
88  
89 0 bless $self,$class;
90  
91 0 $self->tag($a{tag});
92  
93 0 ▶ if ($a{inherit_limit}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a{'inherit_limit'}) { } 0 0 0
94 $self->inherit_limit($a{inherit_limit})
95 0 } else {
96 0 $self->inherit_limit(0)
97 }
98  
99 0 ▶ if ($a{deleted}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a{'deleted'}) { } 0 0 0
100 $self->deleted($a{deleted})
101 0 } else {
102 0 $self->deleted(0)
103 }
104  
105 0 ▶ if ($a{inherit}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a{'inherit'}) { } 0 0 0
106 $self->inherit($a{inherit})
107 0 } else {
108 0 $self->inherit(0)
109 }
110  
111 0 ▶ if ($a{secret}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a{'secret'}) { } 0 0 0
112 $self->secret($a{secret})
113 0 } else {
114 0 $self->secret(0)
115 }
116  
117 0 ▶ if ($a{hide_creator}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a{'hide_creator'}) { } 0 0 0
118 $self->hide_creator($a{hide_creator})
119 0 } else {
120 0 $self->hide_creator(0)
121 }
122  
123 0 ▶ if ($a{dont_garb}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a{'dont_garb'}) { } 0 0 0
124 $self->dont_garb($a{dont_garb})
125 0 } else {
126 0 $self->dont_garb(0)
127 }
128  
129 0 $self->data($a{data});
130  
131 0 ▶ $self->{aux_no} = $a{aux_no} if $a{aux_no};
Branch: 1 branch
BranchTrueFalseTotal
if $a{"aux_no"} 0 0 0
132 0 ▶ $self->{creator} = $a{creator} if $a{creator};
Branch: 1 branch
BranchTrueFalseTotal
if $a{"creator"} 0 0 0
133 0 ▶ $self->{created_at} = $a{created_at} if $a{created_at};
Branch: 1 branch
BranchTrueFalseTotal
if $a{"created_at"} 0 0 0
134  
135 0 return $self;
136 }
137  
138 2 ▶sub new_from_stream {
Subroutine new_from_stream: called CC=2 SCAR=6.9
Pod undocumented
139 2 my $s = {};
140 2 my $class = shift;
141 2 my $arg = $_[0];
142  
143 2 ▶ $class = ref($class) if ref($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 2 2
144 2 bless $s,$class;
145  
146 2 $s->{aux_no} = shift @{$arg};
147 2 $s->{tag} = shift @{$arg};
148 2 $s->{creator} = shift @{$arg};
149 2 $s->{created_at} = Net::Lyskom::Time->new_from_stream($arg);
150 2 my $flags = shift @{$arg};
151 2 $s->{inherit_limit} = shift @{$arg};
152 2 $s->{data} = shift @{$arg};
153  
154 2 my($deleted, $inherit, $secret, $hide_creator, $dont_garb)
155 = $flags =~ m/./g;
156 2 $s->dont_garb($dont_garb);
157 2 $s->hide_creator($hide_creator);
158 2 $s->secret($secret);
159 2 $s->inherit($inherit);
160 2 $s->deleted($deleted);
161  
162 2 return $s;
163 }
164  
165 =item data([$data])
166  
167 Get or set the data attribute of the AuxItem.
168  
169 =cut
170  
171 0 ▶sub data {
Subroutine data: not called CC=2 SCAR=17.9
Pod documented
172 0 my $self = shift;
173  
174 0 ▶ $self->{data} = $_[0] if defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 0 0 0
175 0 return $self->{data};
176 }
177  
178 =item inherit_limit([$limit])
179  
180 Get or set the inherit_limit attribute of the AuxItem.
181  
182 =cut
183  
184 0 ▶sub inherit_limit {
Subroutine inherit_limit: not called CC=2 SCAR=17.9
Pod documented
185 0 my $self = shift;
186  
187 0 ▶ $self->{inherit_limit} = $_[0] if defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 0 0 0
188 0 return $self->{inherit_limit};
189 }
190  
191 =item tag([$tag])
192  
193 Get or set the tag attribute of the AuxItem. It is a fatal error to use
194 a tag type that is not defined in the protocol specification.
195  
196 =cut
197  
198 0 ▶sub tag {
Subroutine tag: not called CC=3 SCAR=24.8
Pod documented
199 0 my $self = shift;
200  
201 0 ▶ return $self->{tag} unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 0 0
202 0 ▶ croak "Unknown AuxItem tag: $_[0]" unless $type{$_[0]};
Branch: 1 branch
BranchTrueFalseTotal
unless $Net::Lyskom::AuxItem::type{$_[0]} 0 0 0
203 0 $self->{tag} = $type{$_[0]};
204 0 return $self->{tag};
205 }
206  
207 =item deleted([$boolean])
208  
209 Get or set the deleted flag of the AuxItem.
210  
211 =cut
212  
213 2 ▶sub deleted {
Subroutine deleted: called CC=3 SCAR=11.7
Pod documented
214 2 my $self = shift;
215  
216 2 ▶ $self->{deleted} = ($_[0])?1:0 if defined $_[0];
Branch: 2 branches
BranchTrueFalseTotal
if defined $_[0] 2 0 2
$_[0] ? : 0 2 2
217 return $self->{deleted}
218 2 }
219  
220 =item inherit([$boolean])
221  
222 Get or set the inherit flag of the AuxItem.
223  
224 =cut
225  
226 2 ▶sub inherit {
Subroutine inherit: called CC=3 SCAR=11.7
Pod documented
227 2 my $self = shift;
228  
229 2 ▶ $self->{inherit} = ($_[0])?1:0 if defined $_[0];
Branch: 2 branches
BranchTrueFalseTotal
if defined $_[0] 2 0 2
$_[0] ? : 0 2 2
230 return $self->{inherit}
231 2 }
232  
233 =item secret([$boolean])
234  
235 Get or set the secret flag of the AuxItem.
236  
237 =cut
238  
239 2 ▶sub secret {
Subroutine secret: called CC=3 SCAR=11.7
Pod documented
240 2 my $self = shift;
241  
242 2 ▶ $self->{secret} = ($_[0])?1:0 if defined $_[0];
Branch: 2 branches
BranchTrueFalseTotal
if defined $_[0] 2 0 2
$_[0] ? : 0 2 2
243 return $self->{secret}
244 2 }
245  
246 =item hide_creator([$boolean])
247  
248 Get or set the hide_creator of the AuxItem.
249  
250 =cut
251  
252 2 ▶sub hide_creator {
Subroutine hide_creator: called CC=3 SCAR=11.7
Pod documented
253 2 my $self = shift;
254  
255 2 ▶ $self->{hide_creator} = ($_[0])?1:0 if defined $_[0];
Branch: 2 branches
BranchTrueFalseTotal
if defined $_[0] 2 0 2
$_[0] ? : 0 2 2
256 return $self->{hide_creator}
257 2 }
258  
259 =item dont_garb([$boolean])
260  
261 Get or set the dont_garb attribute of the AuxItem.
262  
263 =cut
264  
265 2 ▶sub dont_garb {
Subroutine dont_garb: called CC=3 SCAR=11.7
Pod documented
266 2 my $self = shift;
267  
268 2 ▶ $self->{dont_garb} = ($_[0])?1:0 if defined $_[0];
Branch: 2 branches
BranchTrueFalseTotal
if defined $_[0] 2 0 2
$_[0] ? : 0 2 2
269 return $self->{dont_garb}
270 2 }
271  
272 =item aux_no()
273  
274 Get the aux_no attribute of the AuxItem.
275  
276 =cut
277  
278 0 ▶sub aux_no {
Subroutine aux_no: not called CC=2 SCAR=17.9
Pod documented
279 0 my $self = shift;
280  
281 0 ▶ warn "Attempt to set AuxItem aux_no after creation!" if $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 0 0 0
282 0 return $self->{aux_no};
283 }
284  
285 =item creator()
286  
287 Get the creator attribute of the AuxItem.
288  
289 =cut
290  
291 0 ▶sub creator {
Subroutine creator: not called CC=2 SCAR=17.9
Pod documented
292 0 my $self = shift;
293  
294 0 ▶ warn "Attempt to AuxItem set creator after creation!" if $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 0 0 0
295 0 return $self->{creator};
296 }
297  
298 =item created_at()
299  
300 Get the created_at attribute of the AuxItem. Returns a
301 C<Net::Lyskom::Time> object.
302  
303 =cut
304  
305 0 ▶sub created_at {
Subroutine created_at: not called CC=2 SCAR=17.9
Pod documented
306 0 my $self = shift;
307  
308 0 ▶ warn "Attempt to set AuxItem created_at after creation!" if $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 0 0 0
309 return $self->{created_at}
310 0 }
311  
312 =item as_string()
313  
314 Return the object contents as a string.
315  
316 =cut
317  
318 0 ▶sub as_string {
Subroutine as_string: not called CC=3 SCAR=24.8
Pod documented
319 0 my $s = shift;
320 0 my $res = "AuxItem -> { ";
321  
322 0 foreach (keys %{$s}) {
323 0 $res .= sprintf "%s => ",$_;
324 0 ▶ if (ref $s->{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $s->{$_}) { } 0 0 0
325 0 $res .= $s->{$_}->as_string;
326 0 $res .= ", ";
327 } else {
328 0 $res .= sprintf "%s, ",$s->{$_};
329 }
330 }
331 0 $res .= " }";
332 0 return $res;
333 }
334  
335 =item to_server()
336  
337 Return a reference to a four-element array representing this AuxItem,
338 suitable for using as the third argument in a call to
339 Net::Lyskom->create_text()
340  
341 =cut
342  
343 0 ▶sub to_server {
Subroutine to_server: not called CC=6 SCAR=37.4
Pod documented
344 0 my $self = shift;
345 0 my @res;
346  
347 0 $res[0] = $self->tag;
348 0 ▶ $res[1] = sprintf("%s%s%s%s%s000",
Branch: 5 branches
BranchTrueFalseTotal
$self->deleted ? : 0 0 0
$self->inherit ? : 0 0 0
$self->secret ? : 0 0 0
$self->hide_creator ? : 0 0 0
$self->dont_garb ? : 0 0 0
349 $self->deleted?"1":"0",
350 $self->inherit?"1":"0",
351 $self->secret?"1":"0",
352 $self->hide_creator?"1":"0",
353 $self->dont_garb?"1":"0",
354 );
355 0 $res[2] = $self->inherit_limit;
356 0 $res[3] = holl($self->data);
357  
358 0 return @res;
359 }
360  
361 =back
362  
363 =cut
364  
365 1 return 1;
366  
367 =head1 AUTHOR
368  
369 Calle Dybedahl <calle@lysator.liu.se>
370  
371 =cut
372  
« Lyskom.pm ↑ Summary Lyskom/Simple.pm »