File Coverage

blib/lib/Device/Gsm/Sms/Token/DCS.pm
Criterion Covered Total %
statement 15 21 71.4
branch 0 2 0.0
condition 0 5 0.0
subroutine 4 5 80.0
pod n/a
total 19 33 57.5


line stmt bran cond sub pod time code
1             # Sms::Token::DCS - SMS DCS (data coding scheme) 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::DCS;
15 1     1   8 use integer;
  1         2  
  1         6  
16 1     1   31 use strict;
  1         2  
  1         31  
17 1     1   6 use Device::Gsm::Sms::Token;
  1         1  
  1         182  
18              
19             @Sms::Token::DCS::ISA = ('Sms::Token');
20              
21             # takes (scalar message (string) reference)
22             # returns success/failure of decoding
23             # if all ok, removes token from message
24             sub decode {
25 6     6   11 my ($self, $rMessage) = @_;
26 6         10 my $ok = 0;
27              
28 6         32 $self->data(hex substr($$rMessage, 0, 2));
29 6         26 $self->state(Sms::Token::DECODED);
30              
31             # Remove DCS from message
32 6         18 $$rMessage = substr($$rMessage, 2);
33              
34 6         21 return 1;
35             }
36              
37             #
38             # [token]->encode( [$data] )
39             #
40             # takes internal token data and encodes it, returning the result
41             # or undef value in case of errors
42             #
43             sub encode {
44 0     0     my $self = shift;
45              
46             # Take supplied data (optional) or object internal data
47 0           my $data = shift;
48 0 0 0       if (!defined $data || $data eq '') {
49 0           $data = $self->data();
50 0   0       $data ||= '00';
51             }
52              
53 0           return $data;
54             }
55              
56             1;