TOC/Message.pm

filter: Statementstmt 23.6% 27 / 114 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 25.0% 7 / 28 Podpod 80.0% 4 / 5 totaltotal 21.9% 38 / 173 CC 13 SCAR 28.9
CC
13
Cov
20%
new
72.0
new
20.0
isAutoResponse
6.0
CRAP 18.0
↑ Summary TOC.pm »
1 package Net::AIM::TOC::Message;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Net::AIM::TOC::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 0 ▶sub new {
Subroutine new: not called CC=8 SCAR=42.8
Pod undocumented
8 0 my $class = shift;
9 0 my $toc_type = shift;
10 0 my $data = shift;
11  
12 0 my $self;
13  
14 0 ▶ if( $data =~ /^(ERROR):(\d*)(:(.*))?$/ ) {
Branch: 7 branches
BranchTrueFalseTotal
if ($data =~ /^(ERROR):(\d*)(:(.*))?$/) { } 0 0 0
elsif ($data =~ /^(IM_IN):(\w*):([T|F]):(.*)$/) { } 0 0 0
elsif ($data =~ /^(UPDATE_BUDDY):(\w*):([T|F]):(\d):(\d+):(\d+):(.*)?$/) { } 0 0 0
elsif ($data =~ /^(NICK):(.*)$/) { } 0 0 0
elsif ($data =~ /^(SIGN_ON):(.*)$/) { } 0 0 0
elsif ($data =~ /^(PAUSE):(.*)$/) { } 0 0 0
elsif ($data =~ //) { } 0 0 0
15 0 $self = Net::AIM::TOC::Message::ERROR->new( $1, $2, $4, $data );
16 }
17 elsif( $data =~ /^(IM_IN):(\w*):([T|F]):(.*)$/ ) {
18 0 $self = Net::AIM::TOC::Message::IM_IN->new( $1, $2, $3, $4, $data );
19 }
20 elsif( $data =~ /^(UPDATE_BUDDY):(\w*):([T|F]):(\d):(\d+):(\d+):(.*)?$/ ) {
21 0 $self = Net::AIM::TOC::Message::UPDATE_BUDDY->new( $1, $2, $3, $4, $5, $6, $7, $data );
22 }
23 elsif( $data =~ /^(NICK):(.*)$/ ) {
24 0 $self = Net::AIM::TOC::Message::GENERIC->new( $1, $2 );
25 }
26 elsif( $data =~ /^(SIGN_ON):(.*)$/ ) {
27 0 $self = Net::AIM::TOC::Message::GENERIC->new( $1, $2 );
28 }
29 elsif( $data =~ /^(PAUSE):(.*)$/ ) {
30 0 $self = Net::AIM::TOC::Message::GENERIC->new( $1, $2 );
31 }
32 elsif( $data =~ // ) {
33 0 $self = Net::AIM::TOC::Message::BLANK_MESSAGE->new( $data );
34 }
35 else {
36 0 throw Net::AIM::TOC::Error( -text => "Invalid message format: $data" );
37 };
38  
39 0 $self->{_tocType} = $toc_type;
40  
41 0 return( $self );
42 };
43  
44 0 ▶sub getTocType { return( $_[0]->{_tocType} ) };
Subroutine getTocType: not called CC=1 SCAR=6.9
Pod documented
45 0 ▶sub getType { return( $_[0]->{_type} ) };
Subroutine getType: not called CC=1 SCAR=6.9
Pod documented
46 0 ▶sub getMsg { return( $_[0]->{_text} ) };
Subroutine getMsg: not called CC=1 SCAR=6.9
Pod documented
47 0 ▶sub getRawData { return( $_[0]->{_rawData} ) };
Subroutine getRawData: not called CC=1 SCAR=6.9
Pod documented
48  
49  
50  
51 package Net::AIM::TOC::Message::IM_IN;
52  
53 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 1 @Net::AIM::TOC::Message::IM_IN::ISA = qw( Net::AIM::TOC::Message );
56  
57 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
58 0 my $class = shift;
59 0 my $type = shift;
60 0 my $sender = shift;
61 0 my $autoresponse = shift;
62 0 my $msg = shift;
63 0 my $data = shift;
64  
65 0 my $self = {
66 _type => $type,
67 _sender => $sender,
68 _autoResponse => $autoresponse,
69 _text => $msg,
70 _rawData => $data
71 };
72 0 bless $self, $class;
73  
74 0 $self->_removeHtmlTags;
75  
76 0 return( $self );
77 };
78  
79 0 ▶sub _removeHtmlTags {
Subroutine _removeHtmlTags: not called CC=1 SCAR=6.9
80 0 my $self = shift;
81  
82 0 if( Net::AIM::TOC::Config::REMOVE_HTML_TAGS ) {
83 0 $self->{_text} = Net::AIM::TOC::Utils::removeHtmlTags( $self->{_text} );
84 };
85  
86 0 return;
87 }
88  
89  
90 0 ▶sub isAutoResponse {
Subroutine isAutoResponse: not called CC=2 SCAR=17.9
91 0 my $self = shift;
92  
93 0 ▶ if( $self->{_autoResponse} eq 'T' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_autoResponse"} eq "T") 0 0 0
94 0 return( 1 );
95 };
96
97 0 return;
98 };
99  
100 0 ▶sub getSender { return( $_[0]->{_sender} ) };
Subroutine getSender: not called CC=1 SCAR=6.9
101  
102  
103  
104 package Net::AIM::TOC::Message::ERROR;
105  
106 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
107  
108 1 @Net::AIM::TOC::Message::ERROR::ISA = qw( Net::AIM::TOC::Message );
109  
110 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
111 0 my $class = shift;
112 0 my $type = shift;
113 0 my $value = shift;
114 0 ▶ my $text = shift || '';
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
115 0 ▶ my $data = shift || '';
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
116  
117 0 my $self = {
118 _type => $type,
119 _value => $value,
120 _rawData => $data,
121 };
122 0 bless $self, $class;
123  
124 0 $self->{_text} = $self->_getErrorText( $text );
125  
126 0 ▶ unless( $self->isRecoverable ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->isRecoverable) 0 0 0
127 0 throw Net::AIM::TOC::Error( -text => $self->{_text} );
128 };
129  
130 0 return( $self );
131 };
132  
133 0 ▶sub _getErrorText {
Subroutine _getErrorText: not called CC=1 SCAR=6.9
134 0 my $self = shift;
135 0 my $text = shift;
136  
137 0 my $raw_err = Net::AIM::TOC::Config::EVENT_ERROR_STRING( $self->{_value} );
138 0 my $err_text = sprintf( $raw_err, $text );
139  
140 0 return( $err_text );
141 };
142  
143 0 ▶sub isRecoverable {
Subroutine isRecoverable: not called CC=2 SCAR=17.9
144 0 my $self = shift;
145 0 ▶ if( $self->{_value} =~ /^98[0-9]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_value"} =~ /^98[0-9]/) 0 0 0
146 0 return( 0 );
147 }
148 0 return( 1 );
149 };
150  
151  
152  
153 package Net::AIM::TOC::Message::UPDATE_BUDDY;
154  
155 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
156  
157 1 @Net::AIM::TOC::Message::UPDATE_BUDDY::ISA = qw( Net::AIM::TOC::Message );
158  
159 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
160 0 my $class = shift;
161 0 my $type = shift;
162 0 my $buddy = shift;
163 0 my $online = shift;
164 0 my $evil = shift;
165 0 my $signon_time = shift;
166 0 my $idle_time = shift;
167 0 my $user_class = shift;
168 0 my $data = shift;
169  
170 0 my $self = {
171 _type => $type,
172 _buddy => $buddy,
173 _onlineStatus => $online,
174 _evilAmount => $evil,
175 _signonTime => $signon_time,
176 _idleTime => $idle_time,
177 _userClass => $user_class,
178 _rawData => $data,
179 };
180 0 bless $self, $class;
181  
182 0 return( $self );
183 };
184  
185 0 ▶sub getBuddy { return( $_[0]->{_buddy} ) };
Subroutine getBuddy: not called CC=1 SCAR=6.9
186 0 ▶sub getOnlineStatus { return( $_[0]->{_onlineStatus} ) };
Subroutine getOnlineStatus: not called CC=1 SCAR=6.9
187 0 ▶sub getEvilAmount { return( $_[0]->{_evilAmount} ) };
Subroutine getEvilAmount: not called CC=1 SCAR=6.9
188 0 ▶sub getSignonTime { return( $_[0]->{_signonTime} ) };
Subroutine getSignonTime: not called CC=1 SCAR=6.9
189 0 ▶sub getIdleTime { return( $_[0]->{_idleTime} ) };
Subroutine getIdleTime: not called CC=1 SCAR=6.9
190 0 ▶sub getUserClass { return( $_[0]->{_userClass} ) };
Subroutine getUserClass: not called CC=1 SCAR=6.9
191  
192  
193  
194 package Net::AIM::TOC::Message::GENERIC;
195  
196 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
197  
198 1 @Net::AIM::TOC::Message::GENERIC::ISA = qw( Net::AIM::TOC::Message );
199  
200 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
201 0 my $class = shift;
202 0 my $type = shift;
203 0 my $text = shift;
204  
205 0 my $self = {
206 _type => $type,
207 _text => $text,
208 _rawData => $text,
209 };
210 0 bless $self, $class;
211  
212 0 return( $self );
213 };
214  
215  
216  
217 # This sometimes comes through (esp. at signon)
218 package Net::AIM::TOC::Message::BLANK_MESSAGE;
219  
220 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
221  
222 1 @Net::AIM::TOC::Message::BLANK_MESSAGE::ISA = qw( Net::AIM::TOC::Message );
223  
224 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
225 0 my $class = shift;
226 0 my $text = shift;
227  
228 0 my $self = {
229 _type => 'BLANK_MESSAGE',
230 _text => $text,
231 _rawData => $text,
232 };
233 0 bless $self, $class;
234  
235 0 return( $self );
236 };
237  
238  
239  
240 1 1;
241  
242  
243 =pod
244  
245 =head1 NAME
246  
247 Net::AIM::TOC::Message - AIM Message object
248
249 =head1 DESCRIPTION
250  
251 The C<Net::AIM::TOC::Message> object is returned by the C<Net::AIM::TOC::recv_from_aol> method. It provides a simple means of interrogating a received message to find out if it is an incoming instant message, error message, etc.
252  
253 It should never be necessary to create this object.
254  
255 =head1 SYNOPSIS
256  
257 use Error qw( :try );
258 use Net::AIM::TOC;
259  
260 try {
261 my $aim = Net::AIM::TOC->new;
262 $aim->sign_on( $screenname, $password );
263  
264 ...
265  
266 my $msgObj = $aim->recv_from_aol;
267 if( $msgObj->getType eq 'IM_IN' ) {
268 print $msgObj->getMsg, "\n";
269  
270 ...
271
272  
273 =head1 CLASS INTERFACE
274  
275 =head2 OBJECT METHODS
276  
277 =over 4
278  
279 =item getType ()
280  
281 Returns the type of the message. The type can be one of the following (see the Toc PROTOCOL document for a full explanation):
282  
283 -IM_IN
284 -ERROR
285 -UPDATE_BUDDY
286 -NICK
287  
288 =item getMsg ()
289  
290 Returns the content of the message (only available to IM_IN and ERROR messages).
291  
292 =item getRawData ()
293  
294 Returns the raw message as it was received.
295  
296 =item getTocType ()
297  
298 Returns the type of TOC of the message. The type returned is an integer which can be one of the following:
299  
300 -1 (SIGNON)
301 -2 (DATA)
302 -5 (KEEPALIVE)
303  
304 =item getSender ()
305  
306 Returns sender of the instant message (only available to IM_IN messages).
307  
308 =item isAutoResponse ()
309  
310 Returns true if the message was an auto-generated response (only available to IM_IN messages).
311  
312 =item getBuddy ()
313  
314 Returns the buddy name (only available to UPDATE_BUDDY messages).
315  
316 =item getOnlineStatus ()
317  
318 Returns the online status of the buddy (only available to UPDATE_BUDDY messages).
319  
320 =item getEvilAmount ()
321  
322 Returns the evil amount of the buddy (only available to UPDATE_BUDDY messages).
323  
324 =item getSignonTime ()
325  
326 Returns the time (in epoch) at which the buddy signed on (only available to UPDATE_BUDDY messages).
327  
328 =item getIdleTime ()
329  
330 Returns the idle time (in minutes) of the buddy (only available to UPDATE_BUDDY messages).
331  
332 =item getUserClass ()
333  
334 Returns the user class of the buddy (only available to UPDATE_BUDDY messages).
335  
336 =back
337  
338 =head1 KNOWN BUGS
339  
340 None, but that does not mean there are not any.
341  
342 =head1 SEE ALSO
343  
344 C<Net::AIM::TOC>
345  
346 =head1 AUTHOR
347  
348 Alistair Francis, http://search.cpan.org/~friffin/
349  
350 =cut
351  
352  
↑ Summary TOC.pm »