Twilio/Jwt/TaskRouter/Policy.pm

filter: Statementstmt 93.7% 30 / 32 Branchbran 87.5% 14 / 16 Conditioncond 75.0% 6 / 8 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 7 / 7 Podpod 100% 4 / 4 totaltotal 88.7% 63 / 71 CC 12 SCAR 14.4
CC
12
Cov
89%
_with_filter
6.6
new
4.0
to_hash
4.0
CRAP 4.2
« Twilio/ApiV1Version.pm ↑ Summary Twilio/Serialize.pm »
1 package Twilio::Jwt::TaskRouter::Policy;
2  
3 2 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '2.001';
7  
8 71 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
9 71 my ($class, $url, $method, @options) = @_;
10  
11 # A filter left out is an empty one, while undef means no filter at all: the token says so
12 # differently, so the two cannot share a default.
13 71 my ($query_filter, $post_filter, $allow) = @options;
14 71 ▶ return bless {
Branch: 2 branches
BranchTrueFalseTotal
@options > 0 ? : 69 2 71
@options > 1 ? : 69 2 71
Condition100%2/2
$allow // 1
l!l
692
MC/DC100%1/1
$allow // 1
$allow
Truth table100%2/2
A
A= $allow
Aresult
11
00
15 url => $url,
16 method => $method,
17 query_filter => @options > 0 ? $query_filter : {},
18 post_filter => @options > 1 ? $post_filter : {},
19 allow => $allow // 1,
20 }, $class;
21 }
22  
23 2 ▶sub add_query_filter {
Subroutine add_query_filter: called CC=1 SCAR=0.0
Pod documented
24 2 my ($self, $filter) = @_;
25 2 $self->{query_filter} = _with_filter($self->{query_filter}, $filter);
26 2 return;
27 }
28  
29 1 ▶sub add_post_filter {
Subroutine add_post_filter: called CC=1 SCAR=0.0
Pod documented
30 1 my ($self, $filter) = @_;
31 1 $self->{post_filter} = _with_filter($self->{post_filter}, $filter);
32 1 return;
33 }
34  
35 # Filters with no names are a list, and they join named ones under the next free number, which
36 # is what a PHP array does and so what Twilio's clients have always been sent.
37 3 ▶sub _with_filter {
Subroutine _with_filter: called CC=6 SCAR=18.9
38 3 my ($filters, $filter) = @_;
39  
40 3 ▶ return [$filter] if !$filters || (ref $filters eq 'HASH' && !%{$filters});
Branch: 1 branch
BranchTrueFalseTotal
if not $filters or ref $filters eq "HASH" and not %{$filters;} 2 1 3
Condition66%4/6
not $filters or ref $filters eq "HASH" and not %{$filters;}
l!l&&r!l&&!r
021
ref $filters eq "HASH" and not %{$filters;}
!ll&&!rl&&r
012
MC/DC33%1/3
not $filters or ref $filters eq "HASH" and not %{$filters;}
not $filters ref $filters eq "HASH" not %{$filters;}
Truth table50%2/4
not(A) or B and not(C)
A= not $filtersB= ref $filters eq "HASH"C= not %{$filters;}
ABCresult
1XX1
0111
00X0
0100
41 0 ▶ return [@{$filters}, $filter] if ref $filters eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $filters eq "ARRAY" 0 1 1
42  
43 0 my @numbers = sort { $b <=> $a } grep { /\A[0-9]+\z/ } keys %{$filters};
44 1 ▶ return { %{$filters}, (@numbers ? $numbers[0] + 1 : 0) => $filter };
Branch: 1 branch
BranchTrueFalseTotal
@numbers ? : 0 1 1
45 }
46  
47 66 ▶sub to_hash {
Subroutine to_hash: called CC=4 SCAR=13.9
Pod documented
48 66 my ($self) = @_;
49  
50 66 ▶ my %policy = (url => $self->{url}, method => $self->{method}, allow => $self->{allow} ? \1 : \0);
Branch: 1 branch
BranchTrueFalseTotal
$self->{'allow'} ? : 63 3 66
51 66 ▶ $policy{query_filter} = $self->{query_filter} if defined $self->{query_filter};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"query_filter"} 20 46 66
52 66 ▶ $policy{post_filter} = $self->{post_filter} if defined $self->{post_filter};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"post_filter"} 20 46 66
53 66 return \%policy;
54 }
55  
56 2 1;
57  
58 __END__
« Twilio/ApiV1Version.pm ↑ Summary Twilio/Serialize.pm »