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-2015 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             package Sms::Token::OA;
13 3     3   9 use integer;
  3         3  
  3         13  
14 3     3   67 use strict;
  3         3  
  3         41  
15 3     3   9 use Device::Gsm::Sms::Token;
  3         3  
  3         671  
16              
17             @Sms::Token::OA::ISA = ('Sms::Token');
18              
19             # takes (scalar message (string) reference)
20             # returns success/failure of decoding
21             # if all ok, removes OA from message
22             sub decode {
23 14     14   13 my ($self, $rMessage) = @_;
24 14         14 my $ok = 0;
25              
26             # Detect originating address length
27 14         17 my $oa_len = hex(substr $$rMessage, 0, 2);
28              
29             # Get number type (0x91=international, 0x81=local)
30 14         11 my $oa_type = substr($$rMessage, 2, 2);
31              
32             # Number of octets to remove from message
33 14         15 my $oa_octets = (($oa_len + 1) >> 1) << 1;
34              
35             # Get address
36 14         37 my $addr = Device::Gsm::Pdu::decode_address(
37             substr($$rMessage, 0, 4 + $oa_octets));
38              
39 14         38 $self->set('length' => $oa_len);
40 14         19 $self->set('type' => $oa_type);
41 14         17 $self->set('address' => $addr);
42 14         29 $self->data($oa_len, $oa_type, $addr);
43 14         36 $self->state(Sms::Token::DECODED);
44              
45             # Remove OA from message
46 14         20 $$rMessage = substr($$rMessage, 4 + $oa_octets);
47              
48 14         30 return 1;
49             }
50              
51             #
52             # [token]->encode( [$data] )
53             #
54             # encodes originating address (OA)
55             #
56             sub encode {
57 0     0   0 my $self = shift;
58 0         0 my $oa_len = $self->get('length');
59              
60             # XXX TO BE COMPLETED...
61 0         0 return $oa_len;
62              
63             }
64              
65             sub toString {
66 1     1   3 my $self = shift;
67 1         5 my $str = $self->get('address');
68              
69             # Prepend + to number if international
70 1 50 33     9 if ($str !~ /^\s*\+/ && $self->get('type') eq '91') {
71 0         0 $str = '+' . $str;
72             }
73 1         5 return $str;
74             }
75              
76             1;