Asterisk/Zapata.pm

filter: Statementstmt 31.1% 19 / 61 Branchbran 8.3% 3 / 36 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 37.5% 3 / 8 Podpod 0.0% 0 / 6 totaltotal 22.4% 26 / 116 CC 22 SCAR 43.7
CC
22
Cov
23%
readconfig
132.0
channels
90.0
configfile
3.0
CRAP 78.7
« Asterisk/Extension.pm ↑ Summary Asterisk/Voicemail.pm »
1 package Asterisk::Zapata;
2  
3 1 require 5.004;
4  
5 =head1 NAME
6  
7 Asterisk::Zapata - Zapata stuff
8  
9 =head1 SYNOPSIS
10  
11 stuff goes here
12  
13 =head1 DESCRIPTION
14  
15 description
16  
17 =over 4
18  
19 =cut
20  
21 1 ▶use Asterisk;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 $VERSION = '0.01';
24  
25 1 $DEBUG = 5;
26  
27 0 ▶sub version { $VERSION; }
Subroutine version: not called CC=1 SCAR=6.9
Pod undocumented
28  
29 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod undocumented
30 1 my ($class, %args) = @_;
31 1 my $self = {};
32 1 $self->{'configfile'} = undef;
33 1 $self->{'vars'} = {};
34 1 $self->{'channel'} = {};
35  
36 1 ▶ bless $self, ref $class || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
37 # while (my ($key,$value) = each %args) { $self->set($key,$value); }
38 1 return $self;
39 }
40  
41 0 ▶sub DESTROY { }
Subroutine DESTROY: not called CC=1 SCAR=0.0
42  
43 2 ▶sub configfile {
Subroutine configfile: called CC=3 SCAR=11.0
Pod undocumented
44 2 my ($self, $configfile) = @_;
45  
46 2 ▶ if (defined($configfile)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $configfile) { } 1 1 2
47 1 $self->{'configfile'} = $configfile;
48 } else {
49 1 ▶ $self->{'configfile'} = '/etc/asterisk/zapata.conf' if (!defined($self->{'configfile'}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"configfile"} 1 0 1
50 }
51  
52 2 return $self->{'configfile'};
53 }
54  
55 0 ▶sub setvar {
Subroutine setvar: not called CC=1 SCAR=6.9
Pod undocumented
56 0 my ($self, $context, $var, $val) = @_;
57  
58 0 $self->{'vars'}{$context}{$var} = $val;
59 }
60  
61 0 ▶sub channels {
Subroutine channels: not called CC=9 SCAR=45.0
Pod undocumented
62 0 my ($self, $context, $channels) = @_;
63  
64 0 my @chans = ();
65 0 my $channel = '';
66 0 my $x;
67  
68 0 ▶ if ($channels =~ /(\d+)\-(\d+)/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($channels =~ /(\d+)\-(\d+)/) { } 0 0 0
elsif ($channels =~ /^(\d+)$/) { } 0 0 0
elsif ($channels =~ /^\d+,/) { } 0 0 0
69 0 my $beg = $1; my $end = $2;
70 0 ▶ if ($end > $beg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end > $beg) 0 0 0
71 0 ▶ for ($x = $beg; $x <= $end; $x++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x <= $end) 0 0 0
72 0 push(@chans, $x);
73 }
74 }
75 } elsif ($channels =~ /^(\d+)$/) {
76 0 push(@chans, $channels);
77 } elsif ($channels =~ /^\d+,/) {
78 0 push(@chans, split(/,/, $channels));
79 } else {
80 0 ▶ print STDERR "channels got here: $channels\n" if ($DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG 0 0 0
81 }
82  
83 0 foreach $channel (@chans) {
84  
85 0 $self->{'channel'}{$channel}{'channel'} = $channel;
86 0 foreach $var (keys %{$self->{'vars'}{$context}}) {
87 0 $self->{'channel'}{$channel}{$var} = $self->{'vars'}{$context}{$var};
88 }
89 }
90  
91 }
92  
93 0 ▶sub readconfig {
Subroutine readconfig: not called CC=11 SCAR=48.8
Pod undocumented
94 0 my ($self) = @_;
95  
96 0 my $context = '';
97 0 my $line = '';
98  
99 0 my $configfile = $self->configfile();
100  
101 0 ▶ open(CF, "<$configfile") || die "Error loading $configfile: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open CF, "<$configfile" or die "Error loading ${configfile}: $!\n" 0 0 0
102 0 ▶ while ($line = <CF>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline CF)) 0 0 0
103 0 chop($line);
104  
105 0 $line =~ s/;.*$//;
106 0 $line =~ s/\s*$//;
107  
108 0 ▶ if ($line =~ /^;/) {
Branch: 5 branches
BranchTrueFalseTotal
if ($line =~ /^;/) { } 0 0 0
elsif ($line =~ /^\s*$/) { } 0 0 0
elsif ($line =~ /^\[(\w+)\]$/) { } 0 0 0
elsif ($line =~ /^channel\s*[=>]+\s*(.*)$/) { } 0 0 0
elsif ($line =~ /^(\w+)\s*[=>]+\s*(.*)/) { } 0 0 0
109 0 next;
110 } elsif ($line =~ /^\s*$/) {
111 0 next;
112 } elsif ($line =~ /^\[(\w+)\]$/) {
113 0 $context = $1;
114 0 ▶ print STDERR "Context: $context\n" if ($DEBUG>3);
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG > 3 0 0 0
115 } elsif ($line =~ /^channel\s*[=>]+\s*(.*)$/) {
116 0 $channel = $1;
117 0 $self->channels($context, $1);
118 0 ▶ print STDERR "Channel: $channel\n" if ($DEBUG>3);
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG > 3 0 0 0
119 } elsif ($line =~ /^(\w+)\s*[=>]+\s*(.*)/) {
120 0 $self->setvar($context, $1, $2);
121 } else {
122 0 ▶ print STDERR "Unknown line: $line\n" if ($DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG 0 0 0
123 }
124  
125 }
126 0 close(CF);
127  
128 0 return 1;
129 }
130  
131 1 1;
« Asterisk/Extension.pm ↑ Summary Asterisk/Voicemail.pm »