File Coverage

blib/lib/Device/Gsm/Sms/Token/OA.pm
Criterion Covered Total %
statement 26 30 86.6
branch 1 2 50.0
condition 1 3 33.3
subroutine 5 6 83.3
pod n/a
total 33 41 80.4


line stmt bran cond sub pod time code
1             # Sms::Token::OA - SMS OA (originating address) token
2             # Copyright (C) 2002-2006 Cosimo Streppone, cosimo@cpan.org
3             #
4             # This program is free software; you can redistribute it and/or modify
5             # it only under the terms of Perl itself.
6             #
7             # This program is distributed in the hope that it will be useful,
8             # but WITHOUT ANY WARRANTY; without even the implied warranty of
9             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10             # Perl licensing terms for details.
11             #
12             # $Id$
13              
14             package Sms::Token::OA;
15 2     2   11 use integer;
  2         4  
  2         15  
16 2     2   340 use strict;
  2         4  
  2         69  
17 2     2   11 use Device::Gsm::Sms::Token;
  2         4  
  2         800  
18              
19             @Sms::Token::OA::ISA = ('Sms::Token');
20              
21             # takes (scalar message (string) reference)
22             # returns success/failure of decoding
23             # if all ok, removes OA from message
24             sub decode {
25 6     6   15 my ($self, $rMessage) = @_;
26 6         9 my $ok = 0;
27              
28             # Detect originating address length
29 6         14 my $oa_len = hex(substr $$rMessage, 0, 2);
30              
31             # Get number type (0x91=international, 0x81=local)
32 6         15 my $oa_type = substr($$rMessage, 2, 2);
33              
34             # Number of octets to remove from message
35 6         13 my $oa_octets = (($oa_len + 1) >> 1) << 1;
36              
37             # Get address
38 6         35 my $addr = Device::Gsm::Pdu::decode_address(
39             substr($$rMessage, 0, 4 + $oa_octets));
40              
41 6         36 $self->set('length' => $oa_len);
42 6         17 $self->set('type' => $oa_type);
43 6         20 $self->set('address' => $addr);
44 6         26 $self->data($oa_len, $oa_type, $addr);
45 6         41 $self->state(Sms::Token::DECODED);
46              
47             # Remove OA from message
48 6         17 $$rMessage = substr($$rMessage, 4 + $oa_octets);
49              
50 6         25 return 1;
51             }
52              
53             #
54             # [token]->encode( [$data] )
55             #
56             # encodes originating address (OA)
57             #
58             sub encode {
59 0     0   0 my $self = shift;
60 0         0 my $oa_len = $self->get('length');
61              
62             # XXX TO BE COMPLETED...
63 0         0 return $oa_len;
64              
65             }
66              
67             sub toString {
68 1     1   4 my $self = shift;
69 1         8 my $str = $self->get('address');
70              
71             # Prepend + to number if international
72 1 50 33     9 if ($str !~ /^\s*\+/ && $self->get('type') eq '91') {
73 0         0 $str = '+' . $str;
74             }
75 1         7 return $str;
76             }
77              
78             1;