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