| 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
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||
| 47 | 1 | $self->{'configfile'} = $configfile; | |||||||||||||||||||||||||
| 48 | } else { | ||||||||||||||||||||||||||
| 49 | 1 | ▶ | $self->{'configfile'} = '/etc/asterisk/zapata.conf' if (!defined($self->{'configfile'})); | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||
| 69 | 0 | my $beg = $1; my $end = $2; | |||||||||||||||||||||||||
| 70 | 0 | ▶ | if ($end > $beg) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 71 | 0 | ▶ | for ($x = $beg; $x <= $end; $x++) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||
| 102 | 0 | ▶ | while ($line = <CF>) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 103 | 0 | chop($line); | |||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||
| 105 | 0 | $line =~ s/;.*$//; | |||||||||||||||||||||||||
| 106 | 0 | $line =~ s/\s*$//; | |||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ($line =~ /^;/) { | ||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||
| 126 | 0 | close(CF); | |||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||
| 128 | 0 | return 1; | |||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||
| 131 | 1 | 1; | |||||||||||||||||||||||||