| 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
Condition100%2/2
$allow // 1
MC/DC100%1/1
$allow // 1
$allow
Truth table100%2/2
A
A= $allow
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%4/6
not $filters or ref $filters eq "HASH" and not %{$filters;}
ref $filters eq "HASH" and not %{$filters;}
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;}
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | return [@{$filters}, $filter] if ref $filters eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 66 | ▶ | $policy{query_filter} = $self->{query_filter} if defined $self->{query_filter}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 66 | ▶ | $policy{post_filter} = $self->{post_filter} if defined $self->{post_filter}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 66 | return \%policy; | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | __END__ | ||||||||||||||||||||||||||||||||||||||||||