From e4ecca76e93cb5f2822ffc7388920017aa97d27b Mon Sep 17 00:00:00 2001 From: Kirill Solomko Date: Tue, 30 Sep 2014 14:42:03 +0200 Subject: [PATCH] MT#8547 - Fix smartmatch ~~ usage --- lib/NGCP/Panel/Controller/API/Root.pm | 4 ++-- lib/NGCP/Panel/Controller/Root.pm | 8 ++++---- lib/NGCP/Panel/Controller/Statistics.pm | 2 +- lib/NGCP/Panel/Controller/Subscriber.pm | 9 +++++---- lib/NGCP/Panel/Form/Subscriber/SpeedDial.pm | 2 +- lib/NGCP/Panel/Role/API.pm | 6 +++--- lib/NGCP/Panel/Role/API/Subscribers.pm | 4 ++-- lib/NGCP/Panel/Utils/Subscriber.pm | 6 +++--- 8 files changed, 21 insertions(+), 20 deletions(-) diff --git a/lib/NGCP/Panel/Controller/API/Root.pm b/lib/NGCP/Panel/Controller/API/Root.pm index 1d44a2d089..8545c7c10c 100644 --- a/lib/NGCP/Panel/Controller/API/Root.pm +++ b/lib/NGCP/Panel/Controller/API/Root.pm @@ -72,7 +72,7 @@ sub GET : Allow { my $actions = []; if($c->user->read_only) { foreach my $m(keys %{ $full_mod->config->{action} }) { - next unless $m ~~ [qw/GET HEAD OPTIONS/]; + next unless $m =~ /^(GET|HEAD|OPTIONS)$/; push @{ $actions }, $m; } } else { @@ -82,7 +82,7 @@ sub GET : Allow { if($full_item_mod->can('config')) { if($c->user->read_only) { foreach my $m(keys %{ $full_item_mod->config->{action} }) { - next unless $m ~~ [qw/GET HEAD OPTIONS/]; + next unless $m =~ /^(GET|HEAD|OPTIONS)$/; push @{ $item_actions }, $m; } } else { diff --git a/lib/NGCP/Panel/Controller/Root.pm b/lib/NGCP/Panel/Controller/Root.pm index 1becefa855..ed6a3275fb 100644 --- a/lib/NGCP/Panel/Controller/Root.pm +++ b/lib/NGCP/Panel/Controller/Root.pm @@ -80,7 +80,7 @@ sub auto :Private { } else { $c->log->debug("++++++ admin '".$c->user->login."' authenticated via api_admin_cert"); } - if($c->user->read_only && !($c->req->method ~~ [qw/GET HEAD OPTIONS/])) { + if($c->user->read_only && !($c->req->method =~ /^(GET|HEAD|OPTIONS)$/)) { $c->log->error("invalid method '".$c->req->method."' for read-only user '".$c->user->login."', rejecting"); $c->user->logout; $c->response->status(403); @@ -108,7 +108,7 @@ sub auto :Private { } else { $c->log->debug("++++++ admin '".$c->user->login."' authenticated via api_admin_http"); } - if($c->user->read_only && !($c->req->method ~~ [qw/GET HEAD OPTIONS/])) { + if($c->user->read_only && !($c->req->method =~ /^(GET|HEAD|OPTIONS)$/)) { $c->log->error("invalid method '".$c->req->method."' for read-only user '".$c->user->login."', rejecting"); $c->user->logout; $c->response->status(403); @@ -153,7 +153,7 @@ sub auto :Private { $c->req->uri->path =~ /create/ || $c->req->uri->path =~ /edit/ || $c->req->uri->path =~ /delete/ - || !($c->req->method ~~ [qw/GET HEAD OPTIONS/]) + || !($c->req->method =~ /^(GET|HEAD|OPTIONS)$/) )) { $c->detach('/denied_page'); } @@ -227,7 +227,7 @@ sub end :Private { sub _prune_row { my ($columns, %row) = @_; while (my ($k,$v) = each %row) { - unless ($k ~~ $columns) { + unless (grep { $k eq $_ } @$columns) { delete $row{$k}; next; } diff --git a/lib/NGCP/Panel/Controller/Statistics.pm b/lib/NGCP/Panel/Controller/Statistics.pm index 70f833fd01..ff15c107a3 100644 --- a/lib/NGCP/Panel/Controller/Statistics.pm +++ b/lib/NGCP/Panel/Controller/Statistics.pm @@ -30,7 +30,7 @@ sub index :Chained('/') :PathPart('statistics') :Args(0) { my $hosts = NGCP::Panel::Utils::Statistics::get_host_list(); unless($posted) { my $ownhost = hostname; - if($ownhost ~~ @{ $hosts }) { + if(grep { $ownhost eq $_ } @$hosts) { $selected_host = $ownhost; } else { $selected_host = $hosts->[0]; diff --git a/lib/NGCP/Panel/Controller/Subscriber.pm b/lib/NGCP/Panel/Controller/Subscriber.pm index 66a6417d78..68203379fc 100644 --- a/lib/NGCP/Panel/Controller/Subscriber.pm +++ b/lib/NGCP/Panel/Controller/Subscriber.pm @@ -748,10 +748,11 @@ sub preferences :Chained('base') :PathPart('preferences') :Args(0) { }); next unless $preference; my $pref_id = $preference->id; - if($pref =~ /^cf/ && $pref_id ~~ [@attribute_ids]) { + my $pref_id_exists = grep { $pref_id eq $_ } @attribute_ids; + if($pref =~ /^cf/ && $pref_id_exists) { $special_prefs->{callforward}->{active} = 1; $special_prefs->{callforward}->{$pref} = 1; - } elsif($pref_id ~~ [@attribute_ids]) { + } elsif($pref_id_exists) { $special_prefs->{$pref}->{active} = 1; } } @@ -2389,7 +2390,7 @@ sub edit_master :Chained('master') :PathPart('edit') :Args(0) :Does(ACL) :ACLDet my $group = $schema->resultset('voip_subscribers')->find($group_id); next unless($group && $group->provisioning_voip_subscriber && $group->provisioning_voip_subscriber->is_pbx_group); push @new_groups, $group->provisioning_voip_subscriber->id; - unless($group->provisioning_voip_subscriber->id ~~ [ @old_groups ]) { + unless(grep { $group->provisioning_voip_subscriber->id eq $_ } @old_groups) { $prov_subscriber->voip_pbx_groups->create({ group_id => $group->provisioning_voip_subscriber->id, }); @@ -2405,7 +2406,7 @@ sub edit_master :Chained('master') :PathPart('edit') :Args(0) :Does(ACL) :ACLDet } foreach my $group_id(@old_groups) { # remove subscriber from group if not there anymore - unless($group_id ~~ [ @new_groups ]) { + unless(grep { $group_id eq $_ } @new_groups) { my $group = $schema->resultset('provisioning_voip_subscribers')->find($group_id); NGCP::Panel::Utils::Subscriber::update_pbx_group_prefs( c => $c, diff --git a/lib/NGCP/Panel/Form/Subscriber/SpeedDial.pm b/lib/NGCP/Panel/Form/Subscriber/SpeedDial.pm index e266a3fa9c..15abfb85d8 100644 --- a/lib/NGCP/Panel/Form/Subscriber/SpeedDial.pm +++ b/lib/NGCP/Panel/Form/Subscriber/SpeedDial.pm @@ -39,7 +39,7 @@ sub set_slots { } foreach my $s(@{ $self->form->ctx->config->{speed_dial_vsc_presets}->{vsc} }) { - if($s ~~ @used) { + if(grep { $s eq $_ } @used) { next unless(defined $current && $s eq $current); } push @options, { label => $s, value => $s }; diff --git a/lib/NGCP/Panel/Role/API.pm b/lib/NGCP/Panel/Role/API.pm index 3b956602f2..3b4faa907a 100644 --- a/lib/NGCP/Panel/Role/API.pm +++ b/lib/NGCP/Panel/Role/API.pm @@ -203,7 +203,7 @@ sub valid_media_type { my $type; if(ref $media_type eq "ARRAY") { $type = join ' or ', @{ $media_type }; - return 1 if $ctype && $ctype ~~ $media_type; + return 1 if $ctype && grep { $ctype eq $_ } @$media_type; } else { $type = $media_type; return 1 if($ctype && index($ctype, $media_type) == 0); @@ -258,7 +258,7 @@ sub allowed_methods_filtered { if($c->user->read_only) { my @methods = (); foreach my $m(@{ $self->allowed_methods }) { - next unless $m ~~ [qw/GET HEAD OPTIONS/]; + next unless $m =~ /^(GET|HEAD|OPTIONS)$/; push @methods, $m; } return \@methods; @@ -274,7 +274,7 @@ sub allowed_methods { for my $method ($meta->get_method_list) { push @allow, $meta->get_method($method)->name if $meta->get_method($method)->can('attributes') && - 'Allow' ~~ $meta->get_method($method)->attributes; + grep { 'Allow' eq $_ } @{ $meta->get_method($method)->attributes }; } return [sort @allow]; } diff --git a/lib/NGCP/Panel/Role/API/Subscribers.pm b/lib/NGCP/Panel/Role/API/Subscribers.pm index 0f14dd3569..645c1128b3 100644 --- a/lib/NGCP/Panel/Role/API/Subscribers.pm +++ b/lib/NGCP/Panel/Role/API/Subscribers.pm @@ -623,7 +623,7 @@ sub update_item { my @new_groups = (); foreach my $group(@{ $groups }) { push @new_groups, $group->provisioning_voip_subscriber->id; - unless($group->provisioning_voip_subscriber->id ~~ [ @old_groups ]) { + unless(grep { $group->provisioning_voip_subscriber->id eq $_ } @old_groups) { $subscriber->provisioning_voip_subscriber->voip_pbx_groups->create({ group_id => $group->provisioning_voip_subscriber->id, }); @@ -643,7 +643,7 @@ sub update_item { } foreach my $group_id(@old_groups) { # remove subscriber from group if not there anymore - unless($group_id ~~ [ @new_groups ]) { + unless(grep { $group_id eq $_ } @new_groups) { my $group = $schema->resultset('provisioning_voip_subscribers')->find($group_id); NGCP::Panel::Utils::Subscriber::update_pbx_group_prefs( c => $c, diff --git a/lib/NGCP/Panel/Utils/Subscriber.pm b/lib/NGCP/Panel/Utils/Subscriber.pm index 477b0d168a..3a2915bb09 100644 --- a/lib/NGCP/Panel/Utils/Subscriber.pm +++ b/lib/NGCP/Panel/Utils/Subscriber.pm @@ -697,7 +697,7 @@ sub update_subadmin_sub_aliases { my $cli = $num->cc . ($num->ac // '') . $num->sn; my $tmpsubscriber; - if ($num->id ~~ $alias_selected) { + if (grep { $num->id eq $_ } @$alias_selected) { # assign number from someone to this subscriber # since the number could be assigned to any sub within the pbx, @@ -973,7 +973,7 @@ sub apply_rewrite { my $subscriber = $params{subscriber}; my $callee = $params{number}; my $dir = $params{direction}; - return $callee unless $dir ~~ [qw/caller_in callee_in caller_out callee_out/]; + return $callee unless $dir =~ /^(caller_in|callee_in|caller_out|callee_out)$/; my ($field, $direction) = split /_/, $dir; $dir = "rewrite_".$dir."_dpid"; @@ -1019,7 +1019,7 @@ sub apply_rewrite { foreach my $sub($subscriber->contract->voip_subscribers->all) { foreach my $num($sub->voip_numbers->search({ status => 'active' })->all) { my $v = $num->cc . ($num->ac // '') . $num->sn; - unless($v ~~ $cache->{$avp}) { + unless(grep { $v eq $_ } @{ $cache->{$avp} }) { push @{ $cache->{$avp} }, $v; } }