API/Status.pm

filter: Statementstmt 45.7% 27 / 59 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 64.2% 9 / 14 Podpod 33.3% 1 / 3 totaltotal 44.0% 37 / 84 CC 5 SCAR 15.6
CC
5
Cov
40%
new
12.0
AUTOLOAD
12.0
get_type
2.0
CRAP 4.8
« API/Emergency.pm ↑ Summary API/Abbreviation.pm »
1 package Magrathea::API::Status;
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('v0.9.0');
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use experimental qw{ switch };
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Phone::Number;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Attribute::Boolean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use overload q("") => \&stringify;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 =head1 NAME
18  
19 Magrathea::API::Status - A status return for a number
20  
21 =cut
22  
23 sub get_type($)
24 0 ▶{
Subroutine get_type: not called CC=1 SCAR=6.9
Pod undocumented
25 0 my $type = shift;
26 0 given ($type)
27 {
28 when (/^[Ss]:/)
29 0 {
30 0 return 'sip';
31 }
32 when (/^I:/)
33 0 {
34 0 return 'iax2';
35 }
36 when (/^F:/)
37 0 {
38 0 return 'fax2email';
39 }
40 when (/^V:/)
41 0 {
42 0 return 'voice2email';
43 }
44 when (/^\d+$/)
45 0 {
46 0 return 'divert';
47 }
48 0 default {
49 0 return 'unallocated';
50 }
51 }
52 }
53  
54 =head1 CLASS FUNCTIONS
55  
56 =head2 new
57  
58 Usually only called by L<Magrathea::API>.
59  
60 my $status = new Magrathea:API::Status($status);
61  
62 =cut
63  
64 sub new
65 0 ▶{
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
66 0 my $class = shift;
67 0 my $string = shift;
68 0 ▶ return undef if $string =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ /^\s*$/ 0 0 0
69 0 my ($number, $status, $expiry, $target) = split /\s/, $string;
70 0 my $type = get_type $target;
71 0 $target =~ s/.:(.*)/$1/;
72 0 ▶ $target = new Phone::Number($target) if $type eq 'divert';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "divert" 0 0 0
73 0 my $active:Boolean = $status eq 'Y';
74 0 my $self = {
75 number => new Phone::Number($number),
76 active => $active,
77 expiry => $expiry,
78 type => $type,
79 target => $target,
80 entry => 1,
81 };
82 0 bless $self, $class;
83 }
84  
85 sub AUTOLOAD
86 0 ▶{
Subroutine AUTOLOAD: not called CC=3 SCAR=24.8
87 0 my $self = shift;
88 0 my $value = shift;
89 0 (my $name = our $AUTOLOAD) =~ s/.*://;
90 0 ▶ croak "Unknown command: $name" unless defined $self->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$name} 0 0 0
91 0 ▶ $self->{$name} = $value if defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 0 0 0
92 0 return $self->{$name};
93 }
94  
95 sub stringify
96 0 ▶{
Subroutine stringify: not called CC=1 SCAR=6.9
Pod undocumented
97 0 my $self = shift;
98 0 return sprintf '%s %s', $self->type, $self->target;
99 }
100  
101 0 ▶sub DESTROY { }
Subroutine DESTROY: not called CC=1 SCAR=0.0
102  
103 __END__
« API/Emergency.pm ↑ Summary API/Abbreviation.pm »