File Coverage

blib/lib/Device/Gsm/Sms/Token/SCTS.pm
Criterion Covered Total %
statement 25 26 96.1
branch n/a
condition n/a
subroutine 4 5 80.0
pod n/a
total 29 31 93.5


line stmt bran cond sub pod time code
1             # Sms::Token::SCTS - SMS SCTS token (Service Center Time Stamp)
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::SCTS;
13 2     2   5 use integer;
  2         2  
  2         13  
14 2     2   42 use strict;
  2         2  
  2         26  
15 2     2   4 use Device::Gsm::Sms::Token;
  2         2  
  2         379  
16              
17             @Sms::Token::SCTS::ISA = ('Sms::Token');
18              
19             # takes (scalar message (string) reference)
20             # returns success/failure of decoding
21             # if all ok, removes SCTS from message
22             sub decode {
23 12     12   11 my ($self, $rMessage) = @_;
24 12         8 my $ok = 0;
25              
26 12         49 my @ts = split //, substr($$rMessage, 0, 14);
27              
28 12         30 $self->set(year => $ts[1] . $ts[0]);
29 12         25 $self->set(month => $ts[3] . $ts[2]);
30 12         26 $self->set(day => $ts[5] . $ts[4]);
31 12         20 $self->set(hour => $ts[7] . $ts[6]);
32 12         22 $self->set(minute => $ts[9] . $ts[8]);
33 12         17 $self->set(second => $ts[11] . $ts[10]);
34 12         25 $self->set(timezone => $ts[13] . $ts[12]);
35              
36             # Store also timestamp as convenient format
37 12         23 $self->set('date' => $self->get('day') . '/'
38             . $self->get('month') . '/'
39             . $self->get('year'));
40 12         20 $self->set('time' => $self->get('hour') . ':'
41             . $self->get('minute') . ':'
42             . $self->get('second'));
43              
44             # TODO: add timezone decoding ...
45 12         23 $self->data($self->get('date') . ' '
46             . $self->get('time') . ' '
47             . $self->get('timezone'));
48              
49             # Signal token as correctly decoded (?)
50 12         52 $self->state(Sms::Token::DECODED);
51              
52             # Remove SCTS info from message
53 12         15 $$rMessage = substr($$rMessage, 14);
54              
55 12         36 return 1;
56             }
57              
58             #
59             # [token]->encode( [$data] )
60             #
61             # takes internal token data and encodes it, returning the result
62             # or undef value in case of errors
63             #
64             sub encode {
65 0     0     return '99211332959500';
66             }
67              
68             1;