API.pm

filter: Statementstmt 19.4% 38 / 195 Branchbran 0.0% 0 / 94 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 36.3% 12 / 33 Podpod 88.8% 16 / 18 totaltotal 18.1% 66 / 364 CC 55 SCAR 34.6
CC
55
Cov
12%
sendline
90.0
list
56.0
block_allocate
56.0
CRAP 31.7
↑ Summary API/Emergency.pm »
1 package Magrathea::API;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use version 0.77; our $VERSION = qv('v1.6.0');
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Net::Telnet;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Phone::Number;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Email::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Magrathea::API::Status;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Magrathea::API::Emergency;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Attribute::Boolean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 our @CARP_NOT = qw{ Net::Telnet };
20  
21 =encoding utf8
22  
23 =head2 NAME
24  
25 Magrathea::API - Easier access to the Magrathea NTS API
26  
27 =head2 VERSION
28  
29 Version 1.6.0
30  
31 =head2 SYNOPSIS
32  
33 use Magrathea::API;
34 my $mt = new Magrathea::API;
35 my $number = $mt->allocate('01792');
36 $mt->deactivate($number);
37 my @list = $mt->list('01792');
38 my @numbers = $mt->block_allocate('01792', 10);
39 $mt->fax2email($numbers[2], 'user@host.com');
40 $mt->divert($number[3], '+5716027171');
41 $emerg = $mt->emergency_info;
42  
43 =head2 DESCRIPTION
44  
45 This module implements most of the
46 L<Magrathea NTS API|https://www.magrathea-telecom.co.uk/assets/Client-Downloads/Numbering-API-Instructions.pdf>
47 in a simple format.
48  
49 =head2 EXPORT
50  
51 Nothing Exported.
52  
53 =cut
54  
55 #################################################################
56 ##
57 ## Local Prototyped Functions
58 ##
59 #################################################################
60  
61 sub catch(;$)
62 0 ▶{
Subroutine catch: not called CC=4 SCAR=30.0
Pod undocumented
63 0 local $_ = $@;
64 0 ▶ return undef unless $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 0 0 0
65 0 chomp;
66 0 my $re = shift;
67 0 ▶ return true if ref $re eq 'Regexp' and $_ =~ $re;
Branch: 1 branch
BranchTrueFalseTotal
if ref $re eq "Regexp" and $_ =~ /$re/ 0 0 0
Condition0%0/3
ref $re eq "Regexp" and $_ =~ /$re/
!ll&&!rl&&r
000
MC/DC0%0/2
ref $re eq "Regexp" and $_ =~ /$re/
ref $re eq "Regexp" $_ =~ /$re/
Truth table0%0/3
A and B
A= ref $re eq "Regexp"B= $_ =~ /$re/
ABresult
0X0
100
111
68 0 croak $_;
69 }
70  
71 #################################################################
72 ##
73 ## Private Instance Functions
74 ##
75 #################################################################
76  
77 sub sendline
78 0 ▶{
Subroutine sendline: not called CC=9 SCAR=45.0
Pod undocumented
79 0 my $self = shift;
80 0 ▶ my $message = shift // '';
Condition0%0/2
shift() // ""
l!l
00
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
81 0 ▶ say ">> $message" if $self->{params}{debug} && $message;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"params"}{"debug"} and $message 0 0 0
Condition0%0/3
$self->{"params"}{"debug"} and $message
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"params"}{"debug"} and $message
$self->{"params"}{"debug"} $message
Truth table0%0/3
A and B
A= $self->{"params"}{"debug"}B= $message
ABresult
0X0
100
111
82 0 ▶ $self->{telnet}->print($message) if $message;
Branch: 1 branch
BranchTrueFalseTotal
if $message 0 0 0
83 0 my $response = $self->{telnet}->getline;
84 0 ▶ croak 'Error in getline' unless defined $response;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $response 0 0 0
85 0 chomp $response;
86 0 my ($val, $msg) = $response =~ /^(\d)\s+(.*)/;
87 0 ▶ croak qq(Unknown response: "$response") unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
88 0 ▶ say "<<$val $msg" if $self->{params}{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"params"}{"debug"} 0 0 0
89 0 ▶ croak "$msg" unless $val == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $val == 0 0 0 0
90 0 return $val, $msg;
91 }
92  
93 #################################################################
94 ##
95 ## Class Functions
96 ##
97 #################################################################
98  
99 =head2 MAIN API METHODS
100  
101 =head2 Constructor
102  
103 =head3 new
104  
105 This will create a new Magrathea object and open at telnet
106 session to the server. If authorisation fails, it will croak.
107  
108 my $mt = new Magrathea::API(
109 username => 'myuser',
110 password => 'mypass',
111 );
112  
113 =head4 Parameters:
114  
115 =over
116  
117 =item username
118  
119 =item password
120  
121 The username and password allocated by Magrathea.
122  
123 =item host
124  
125 Defaults to I<api.magrathea-telecom.co.uk> but could be overridden.
126  
127 =item port
128  
129 Defaults to I<777>.
130  
131 =item timeout
132  
133 In seconds. Defaults to I<10>.
134  
135 =item debug
136  
137 If set to a true value, this will output the conversation between the API
138 and Magrathea's server. Be careful as this will also echo the username
139 and password.
140  
141 =back
142  
143 =cut
144  
145 sub new
146 0 ▶{
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
147 0 my $class = shift;
148 0 my %defaults = (
149 host => 'api.magrathea-telecom.co.uk',
150 port => 777,
151 timeout => 10,
152 debug => false,
153 );
154 0 my %params = (%defaults, @_);
155 croak "Username & Password Required"
156 0 ▶ unless $params{username} && $params{password};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"username"} and $params{"password"} 0 0 0
Condition0%0/3
$params{"username"} and $params{"password"}
!ll&&!rl&&r
000
MC/DC0%0/2
$params{"username"} and $params{"password"}
$params{"username"} $params{"password"}
Truth table0%0/3
A and B
A= $params{"username"}B= $params{"password"}
ABresult
0X0
100
111
157 my $telnet = new Net::Telnet(
158 Host => $params{host},
159 Port => $params{port},
160 Timeout => $params{timeout},
161 0 ▶ Errmode => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
162 0 croak shift;
163 },
164 0 );
165 0 my $self = {
166 params => \%params,
167 telnet => $telnet,
168 };
169 0 bless $self, $class;
170 0 $self->sendline;
171 0 eval {
172 0 $self->auth(@params{qw(username password)});
173 };
174 0 catch;
175 0 return $self;
176 }
177  
178 #################################################################
179 ##
180 ## Instance Functions
181 ##
182 #################################################################
183  
184 =head2 Allocation Methods
185  
186 In all cases where C<$number> is passed, this may be a string
187 containing a number in National format (I<020 1234 5678>) or
188 in International format (I<+44 20 1234 5678>). Spaces are ignored.
189 Also, L<Phone::Number> objects may be passed.
190  
191 When a number is returned, it will always be in the for of a
192 L<Phone::Number> object.
193  
194 =head3 allocate
195  
196 Passed a prefix, this will allocate and activate a number. You do not need
197 to add the C<_> characters. If a number can be found, this routine
198 will return a L<Phone::Number> object. If no match is found, this
199 routine will return C<undef>. It will croak on any other error from
200 Magrathea.
201  
202 =cut
203  
204 sub allocate
205 0 ▶{
Subroutine allocate: not called CC=4 SCAR=30.0
Pod documented
206 0 my $self = shift;
207 0 my $number = shift;
208 0 $number = substr $number . '_' x 11, 0, 11;
209 0 ▶ for (my $tries = 0; $tries < 5; $tries++)
Branch: 1 branch
BranchTrueFalseTotal
if ($tries < 5) 0 0 0
210 {
211 0 eval {
212 0 my $result = $self->allo($number);
213 0 ($number = $result) =~ s/\s.*$//;
214 };
215 0 ▶ return undef if catch qr/^No number found for allocation/;
Branch: 1 branch
BranchTrueFalseTotal
if &catch(qr/^No number found for allocation/) 0 0 0
216 0 eval {
217 0 $self->acti($number);
218 };
219 0 ▶ unless (catch qr/^Number not activated/) # $@ is ''
Branch: 1 branch
BranchTrueFalseTotal
unless (&catch(qr/^Number not activated/)) 0 0 0
220 {
221 0 return new Phone::Number($number);
222 }
223 }
224 0 return undef; # Failed after 5 attempts.
225 }
226  
227 =head3 activate
228  
229 Passed a number as a string or a L<Phone::Number>, this will
230 activate that number.
231  
232 =cut
233  
234 sub activate
235 0 ▶{
Subroutine activate: not called CC=2 SCAR=17.9
Pod documented
236 0 my $self = shift;
237 0 my $number = new Phone::Number(shift);
238 0 ▶ $self->acti($number->uk ? $number->packed : $number->number);
Branch: 1 branch
BranchTrueFalseTotal
$number->uk ? : 0 0 0
239 }
240  
241 =head3 deactivate
242  
243 Passed a number as a string or a L<Phone::Number>, this deactivates
244 the number.
245  
246 =cut
247  
248 sub deactivate
249 0 ▶{
Subroutine deactivate: not called CC=2 SCAR=17.9
Pod documented
250 0 my $self = shift;
251 0 my $number = new Phone::Number(shift);
252 0 ▶ $self->deac($number->uk ? $number->packed : $number->number);
Branch: 1 branch
BranchTrueFalseTotal
$number->uk ? : 0 0 0
253 }
254  
255 =head3 reactivate
256  
257 Reactivates a number that has previously been deactivated.
258  
259 =cut
260  
261 sub reactivate
262 0 ▶{
Subroutine reactivate: not called CC=2 SCAR=17.9
Pod documented
263 0 my $self = shift;
264 0 my $number = new Phone::Number(shift);
265 0 ▶ $self->reac($number->uk ? $number->packed : $number->number);
Branch: 1 branch
BranchTrueFalseTotal
$number->uk ? : 0 0 0
266 }
267  
268 =head3 list
269  
270 This should be passed a prefix and possibly a quantity (defaulting
271 to 10. It will return a sorted random list of available numbers matching
272 the prefix. These are returned as an array (or an arrayref) of
273 L<Phone::Number>. None of the numbers is allocated by this method.
274  
275 If none are available, the method will return an empty array.
276  
277 =cut
278  
279 sub list
280 0 ▶{
Subroutine list: not called CC=7 SCAR=40.3
Pod documented
281 0 my $self = shift;
282 0 my $prefix = shift;
283 0 ▶ my $qty = shift // 10;
Condition0%0/2
shift() // 10
l!l
00
MC/DC0%0/1
shift() // 10
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
284 0 local $_;
285 0 my @results;
286 0 eval {
287 0 push @results, new Phone::Number($self->alist($prefix, $qty));
288 };
289 0 ▶ unless (catch qr/^No range found for allocation/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&catch(qr/^No range found for allocation/)) 0 0 0
290 0 ▶ while (true) {
Branch: 1 branch
BranchTrueFalseTotal
if (&true()) 0 0 0
291 0 my $response = $self->{telnet}->getline;
292 0 chomp $response;
293 0 my ($val, $msg) = $response =~ /^(\d)\s+(.*)/;
294 0 ▶ say "<<$val $msg" if $self->{params}{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"params"}{"debug"} 0 0 0
295 0 ▶ last if $val != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $val != 0 0 0 0
296 0 push @results, new Phone::Number($msg);
297 }
298 0 @results = sort { $a->plain cmp $b->plain } @results;
299 }
300 0 ▶ return wantarray ? @results : \@results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
301  
302 }
303  
304 =head2 Block Methods
305  
306 =head3 block_allocate
307  
308 This should be passed a prefix (without any C<_> characters) and an
309 optional block size (defaulting to 10). It will attempt to allocate
310 and activate a block of numbers.
311  
312 If a block can be found, this routine
313 should return an array or arrayref of L<Phone::Number> objects. Under odd
314 circumstances, it is possible that fewer than the requested quantity
315 of numbers will be returned;
316  
317 If no range is found is found, this routine will return C<undef> in scalar
318 context or an empty array in list context. It will croak
319 on any other error from Magrathea.
320  
321 =cut
322  
323 sub block_allocate
324 0 ▶{
Subroutine block_allocate: not called CC=7 SCAR=40.3
Pod documented
325 0 my $self = shift;
326 0 my $range = shift;
327 0 ▶ my $qty = shift // 10;
Condition0%0/2
shift() // 10
l!l
00
MC/DC0%0/1
shift() // 10
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
328 0 local $_;
329 0 ▶ croak "Block size must be a number" unless $qty =~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $qty =~ /^\d+$/ 0 0 0
330 0 my $alloc = eval {
331 0 $self->blkacti($range, $qty);
332 };
333 0 ▶ if (catch qr/^No range found for allocation/) {
Branch: 1 branch
BranchTrueFalseTotal
if (&catch(qr/^No range found for allocation/)) 0 0 0
334 0 ▶ return wantarray ? () : undef;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
335 }
336 0 my ($first, $last) = split ' ', $alloc;
337 0 my @numbers;
338 0 ▶ while ($first le $last) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first le $last) 0 0 0
339 0 push @numbers, new Phone::Number($first++);
340 }
341 0 ▶ return wantarray ? @numbers : \@numbers;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
342 }
343  
344 =head3 block_info
345  
346 This should be passed a number (string or L<Phone::Number>)
347 to check whether that number is part of a block.
348  
349 If it is, the size of the block will be returned in scalar context;
350 In list context, the response will be an array of all the numbers
351 in that block.
352  
353 If it is not a block, this will return C<undef> or an empty
354 array.
355  
356 =cut
357  
358 sub block_info
359 0 ▶{
Subroutine block_info: not called CC=6 SCAR=37.4
Pod documented
360 0 my $self = shift;
361 0 my $number = new Phone::Number(shift);
362 0 my $block = eval {
363 0 ▶ $self->blkinfo($number->uk ? $number->packed : $number->number);
Branch: 1 branch
BranchTrueFalseTotal
$number->uk ? : 0 0 0
364 };
365 0 ▶ if (catch qr/^Account not ACTIve/) {
Branch: 1 branch
BranchTrueFalseTotal
if (&catch(qr/^Account not ACTIve/)) 0 0 0
366 0 ▶ return wantarray ? () : undef;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
367 }
368 0 my ($first, $qty) = split ' ', $block;
369 0 ▶ return 0 + $qty unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 0 0
370 0 my @numbers;
371 0 ▶ for (; $qty > 0; $qty--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qty > 0) 0 0 0
372 0 push @numbers, new Phone::Number($first++);
373 }
374 0 return @numbers;
375 }
376  
377 =head3 block_deactivate
378  
379 This should be passed the first number in a block. It will
380 deactivate and return the block of numbers.
381  
382 =cut
383  
384 sub block_deactivate
385 0 ▶{
Subroutine block_deactivate: not called CC=2 SCAR=17.9
Pod documented
386 0 my $self = shift;
387 0 my $number = new Phone::Number(shift);
388 0 ▶ $self->blkdeac($number->uk ? $number->packed : $number->number);
Branch: 1 branch
BranchTrueFalseTotal
$number->uk ? : 0 0 0
389 }
390  
391 =head3 block_reactivate
392  
393 This should be passed the first number in a block. It will
394 reactivate the block and return the size of the block in scalar
395 context or an array of the numbers in list context.
396  
397 If the block is not available, this method will croak.
398  
399 In testing, this method has never worked correctly.
400  
401 =cut
402  
403 sub block_reactivate
404 0 ▶{
Subroutine block_reactivate: not called CC=2 SCAR=17.9
Pod documented
405 0 my $self = shift;
406 0 my $number = new Phone::Number(shift);
407 0 ▶ $self->blkreac($number->uk ? $number->packed : $number->number);
Branch: 1 branch
BranchTrueFalseTotal
$number->uk ? : 0 0 0
408 }
409  
410 =head2 Service Methods
411  
412 =head3 fax2email
413  
414 Sets a number as a fax to email.
415  
416 $mt->fax2email($number, $email_address);
417  
418 =cut
419  
420 sub fax2email
421 0 ▶{
Subroutine fax2email: not called CC=3 SCAR=24.8
Pod documented
422 0 my $self = shift;
423 0 my $number = new Phone::Number(shift);
424 0 my $email = shift;
425 0 my @email = parse Email::Address($email);
426 0 ▶ croak "One email address required" if @email != 1;
Branch: 1 branch
BranchTrueFalseTotal
if @email != 1 0 0 0
427 0 ▶ my $num = $number->uk ? $number->packed : $number->number;
Branch: 1 branch
BranchTrueFalseTotal
$number->uk ? : 0 0 0
428 0 $self->set($num, 1, "F:$email[0]");
429 }
430  
431 =head3 voice2email
432  
433 Sets a number as a voice to email.
434  
435 $mt->voice2email($number, $email_address);
436  
437 =cut
438  
439 sub voice2email
440 0 ▶{
Subroutine voice2email: not called CC=3 SCAR=24.8
Pod documented
441 0 my $self = shift;
442 0 my $number = new Phone::Number(shift);
443 0 my $email = shift;
444 0 my @email = parse Email::Address($email);
445 0 ▶ croak "One email address required" if @email != 1;
Branch: 1 branch
BranchTrueFalseTotal
if @email != 1 0 0 0
446 0 ▶ my $num = $number->uk ? $number->packed : $number->number;
Branch: 1 branch
BranchTrueFalseTotal
$number->uk ? : 0 0 0
447 0 $self->set($num, 1, "V:$email[0]");
448 }
449  
450 =head3 sip
451  
452 $mt->sip($number, $host, [$username, [$inband]]);
453  
454 Passed a number and a host, will set an inbound sip link
455 to the international number (minus leading +) @ the host.
456 If username is defined, it will be used instead of the number.
457 If inband is true, it will force inband DTMF. The default is
458 RFC2833 DTMF.
459  
460 =cut
461  
462 sub sip
463 0 ▶{
Subroutine sip: not called CC=5 SCAR=34.0
Pod documented
464 0 my $self = shift;
465 0 my $number = new Phone::Number(shift);
466 0 my ($host, $username, $inband) = @_;
467 0 ▶ croak "Domain required" unless $host;
Branch: 1 branch
BranchTrueFalseTotal
unless $host 0 0 0
468 0 ▶ $username = $number->plain unless $username;
Branch: 1 branch
BranchTrueFalseTotal
unless $username 0 0 0
469 0 ▶ my $sip = $inband ? "s" : "S";
Branch: 1 branch
BranchTrueFalseTotal
$inband ? : 0 0 0
470 0 ▶ my $num = $number->uk ? $number->packed : $number->number;
Branch: 1 branch
BranchTrueFalseTotal
$number->uk ? : 0 0 0
471 0 $self->set($num, 1, "$sip:$username\@$host");
472 }
473  
474 =head3 divert
475  
476 $mt->divert($number, $to_number);
477  
478 =cut
479  
480 sub divert
481 0 ▶{
Subroutine divert: not called CC=2 SCAR=17.9
Pod documented
482 0 my $self = shift;
483 0 my $number = new Phone::Number(shift);
484 0 my $to = new Phone::Number(shift);
485 0 ▶ my $num = $number->uk ? $number->packed : $number->number;
Branch: 1 branch
BranchTrueFalseTotal
$number->uk ? : 0 0 0
486 0 $self->set($num, 1, $to->plain);
487 }
488  
489  
490 =head3 status
491  
492 Returns the status for a given number.
493  
494 my $status = $mt->status($number);
495 my @status = $mt->status($number);
496  
497 In scalar context, returns the first (and usually only) status as
498 a L<Magrathea::API::Status> object. In list context, returns up to
499 three statuses representing the three possible setups created with
500 ORDE.
501  
502 If the number is not allocated to us and activated, this routine
503 returns C<undef> in scalar context and an empty list in list context.
504  
505 The L<Magrathea::API::Status> object has the following calls:
506  
507 =over
508  
509 =item C<< $status->number >>
510  
511 A L<Phone::Number> object representing the number to which this
512 status refers.
513  
514 =item C<< $status->active >>
515  
516 Boolean.
517  
518 =item C<< $status->expiry >>
519  
520 The date this number expires in the form C<YYYY-MM-DD>.
521  
522 =item C<< $status->type >>
523  
524 One of sip, fax2email, voice2email, divert or unallocated.
525  
526 =item C<< $status->target >>
527  
528 The target email or phone number for this number;
529  
530 =item C<< $status->entry >>
531  
532 The entry number (1, 2 or 3) for this status;
533  
534 =back
535  
536 In addition, it overloads '""' to provide as tring comprising
537 the type and the target, separated by a space.
538  
539 =cut
540  
541 sub status
542 0 ▶{
Subroutine status: not called CC=7 SCAR=40.3
Pod documented
543 0 my $self = shift;
544 0 my $number = new Phone::Number(shift);
545 0 my $status = eval {
546 0 ▶ $self->stat($number->uk ? $number->packed : $number->number);
Branch: 1 branch
BranchTrueFalseTotal
$number->uk ? : 0 0 0
547 };
548 0 ▶ return wantarray ? () : undef if $@;
Branch: 2 branches
BranchTrueFalseTotal
if $@ 0 0 0
wantarray ? : 0 0 0
549 0 my @statuses = split /\|/, $status;
550 0 my @retval;
551 0 for my $i (0 .. 2)
552 {
553 0 my $stat = new Magrathea::API::Status($statuses[$i]);
554 0 ▶ return $stat unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 0 0
555 0 ▶ next unless $stat;
Branch: 1 branch
BranchTrueFalseTotal
unless $stat 0 0 0
556 0 $stat->entry($i + 1);
557 0 push @retval, $stat;
558 }
559 0 return @retval;
560 }
561  
562 =head2 Emergency Methods
563  
564 =head3 emergency_info
565  
566 Passed a phone number, this method returns a
567 L<Magrathea::API::Emergency> object with the current 999
568 information.
569  
570 Optionally it can be passed a second parameter which, if it
571 is a truthy value, will set the C<ported> flag.
572  
573 =cut
574  
575 sub emergency_info
576 0 ▶{
Subroutine emergency_info: not called CC=1 SCAR=6.9
Pod documented
577 0 my $self = shift;
578 0 my $number = new Phone::Number(shift);
579 0 my $ported = shift;
580 0 return new Magrathea::API::Emergency($self, $number, $ported);
581 }
582  
583 =head2 Low Level Methods
584  
585 All the Magrathea low level calls are available. These are
586 simply passed an array of strings which are joined to create
587 the command string. They return the raw response
588 on success (minus the leading 0) and die on failure. C<$@>
589 will contain the error.
590  
591 See the L<Magrathea documentation|http://www.magrathea-telecom.co.uk/assets/Client-Downloads/Numbering-API-Instructions.pdf>.
592  
593 The functions are:
594  
595 =over
596  
597 =item auth
598  
599 This is called by L</new> and should not be called directly.
600  
601 $mt->auth('username', 'password');
602  
603 =item quit
604  
605 This is called automatically upon the Magrathea::API object
606 going out of scope and should not be called directly.
607  
608 =item allo
609  
610 $mt->allo('0201235___');
611  
612 =item acti
613  
614 $mt->acti('02012345678');
615  
616 =item deac
617  
618 $mt->deac('02012345678');
619  
620 =item reac
621  
622 $mt->reac('02012345678');
623  
624 =item stat
625  
626 $mt->stat('02012345678');
627  
628 =item set
629  
630 $mt->set('02012345678 1 441189999999');
631 $mt->set('02012345678 1 F:fax@mydomain.com');
632 $mt->set('02012345678 1 V:voicemail@mydomain.com');
633 $mt->set('02012345678 1 S:username@sip.com');
634 $mt->set('02012345678 1 I:username:password@iaxhost.com');
635  
636 =item spin
637  
638 $mt->set('02012345678 [pin]');
639  
640 =item feat
641  
642 $mt->feat('02012345678 D');
643 $mt->feat('02012345678 J');
644  
645 =item orde
646  
647 $mt->orde('02012345678 1 0000');
648  
649 =item info
650  
651 $mt->info('02012345678 GEN Magrathea, 14 Shute End, RG40 1BJ');
652  
653 =back
654  
655 It will not usually be necessary to call these functions directly.
656  
657 =cut
658  
659 sub AUTOLOAD
660 0 ▶{
Subroutine AUTOLOAD: not called CC=2 SCAR=17.9
661 0 my $self = shift;
662 0 my $commands = qr{^(?:
663 AUTH|QUIT|ALLO|ACTI|DEAC|REAC|STAT|SET|SPIN|FEAT|ORDE|INFO|ALIST|
664 BLKACTI|BLKINFO|BLKDEAC|BLKREAC
665 )$}x;
666 0 (my $name = our $AUTOLOAD) =~ s/.*://;
667 0 my $cmd = uc $name;
668 0 ▶ croak "Unknown Command: $name" unless $cmd =~ $commands;
Branch: 1 branch
BranchTrueFalseTotal
unless $cmd =~ /$commands/ 0 0 0
669 0 return $self->sendline("$cmd @_");
670 }
671  
672 sub DESTROY
673 0 ▶{
Subroutine DESTROY: not called CC=1 SCAR=6.9
674 0 my $self = shift;
675 0 eval {
676 0 $self->quit;
677 };
678 }
679  
680 1 1;
681  
682 __END__
↑ Summary API/Emergency.pm »