line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SMS::Handler::Utils; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require 5.005_62; |
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
59455
|
use strict; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
211
|
|
6
|
5
|
|
|
5
|
|
29
|
use warnings; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
2946
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# $Id: Utils.pm,v 1.4 2003/01/03 02:03:34 lem Exp $ |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = q$Revision: 1.4 $; |
12
|
|
|
|
|
|
|
$VERSION =~ s/Revision: //; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw(Split Split_msg); |
15
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=pod |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 NAME |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
SMS::Handler::Utils - Utility functions used by some SMS::Handler modules |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
use SMS::Handler::Utils; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
... |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
This module provides various utility functions for use by |
32
|
|
|
|
|
|
|
C modules. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
The exported functions are: |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=over 3 |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=item C |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Separates an incoming SMS into a command and body section. It is |
41
|
|
|
|
|
|
|
separated either by the first newline or the first occurrence of two |
42
|
|
|
|
|
|
|
consecutive spaces. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub Split |
47
|
|
|
|
|
|
|
{ |
48
|
8
|
|
|
8
|
1
|
7767
|
my $msg = shift; |
49
|
8
|
|
|
|
|
10
|
my $body; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $i; |
52
|
|
|
|
|
|
|
|
53
|
8
|
|
|
|
|
88
|
($msg, $body) = split(qr(\n| ), $msg, 2); |
54
|
|
|
|
|
|
|
|
55
|
8
|
100
|
|
|
|
33
|
$body = '' unless defined $body; |
56
|
|
|
|
|
|
|
|
57
|
8
|
|
|
|
|
29
|
return $msg, $body; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=pod |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=item C |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Splits the given message (passed as a reference to a scalar) into |
65
|
|
|
|
|
|
|
C<$maxlen> characters wide messages. Returns an array of scalar |
66
|
|
|
|
|
|
|
references pointing to each chunk, which include a counter. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub Split_msg |
71
|
|
|
|
|
|
|
{ |
72
|
4
|
|
|
4
|
1
|
4481
|
my $maxlen = shift; |
73
|
4
|
|
|
|
|
7
|
my $text = shift; |
74
|
|
|
|
|
|
|
|
75
|
4
|
|
|
|
|
6
|
my @msg = (); |
76
|
|
|
|
|
|
|
|
77
|
4
|
|
|
|
|
6
|
my $join = '...'; |
78
|
4
|
|
|
|
|
5
|
my $sjoin = length($join); |
79
|
4
|
|
|
|
|
6
|
my $size = $maxlen - $sjoin; |
80
|
|
|
|
|
|
|
|
81
|
4
|
|
|
|
|
46
|
push @msg, $_ while $_ = substr($$text, 0, $size - 4, ''); |
82
|
|
|
|
|
|
|
|
83
|
4
|
|
|
|
|
6
|
my $change; |
84
|
|
|
|
|
|
|
# Now iterate through the list of chunks |
85
|
|
|
|
|
|
|
# fixing lengths up. |
86
|
|
|
|
|
|
|
do |
87
|
4
|
|
|
|
|
4
|
{ |
88
|
4
|
|
|
|
|
7
|
$change = 0; |
89
|
4
|
|
|
|
|
10
|
for my $c (0 .. $#msg) |
90
|
|
|
|
|
|
|
{ |
91
|
|
|
|
|
|
|
# warn "# Checking $c $msg[$c] " . scalar @msg . "\n"; |
92
|
9
|
50
|
|
|
|
55
|
if (length($msg[$c]) |
93
|
|
|
|
|
|
|
+ length($c) |
94
|
|
|
|
|
|
|
+ length(scalar @msg) + 2 > $size) |
95
|
|
|
|
|
|
|
{ |
96
|
0
|
0
|
|
|
|
0
|
$msg[$c + 1] = '' unless $msg[$c + 1]; |
97
|
0
|
|
|
|
|
0
|
substr($msg[$c + 1], 0, 0, |
98
|
|
|
|
|
|
|
substr($msg[$c], |
99
|
|
|
|
|
|
|
$size |
100
|
|
|
|
|
|
|
- length($msg[$c]) |
101
|
|
|
|
|
|
|
- length($c) |
102
|
|
|
|
|
|
|
- length(scalar @msg) |
103
|
|
|
|
|
|
|
- 2 |
104
|
|
|
|
|
|
|
- $sjoin, length($msg[$c]), '')); |
105
|
0
|
|
|
|
|
0
|
$change = 1; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} while $change; |
109
|
|
|
|
|
|
|
# Fixup the strings in each chunk |
110
|
4
|
|
|
|
|
6
|
my $c = 0; |
111
|
|
|
|
|
|
|
|
112
|
9
|
100
|
|
|
|
55
|
return [ map |
113
|
4
|
|
|
|
|
8
|
{ ++$c . '/' . scalar @msg . "\n$_" . |
114
|
|
|
|
|
|
|
($c < scalar @msg ? $join : ''); |
115
|
|
|
|
|
|
|
} @msg ]; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
__END__ |