| 1 | 5 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 2 | 5 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | |||||||||||||
| 4 | package Dancer2::Plugin::UnicodeNormalize; | ||||||||||||
| 5 | { | ||||||||||||
| 6 | 5 | $Dancer2::Plugin::UnicodeNormalize::VERSION = '0.04'; | |||||||||||
| 7 | } | ||||||||||||
| 8 | |||||||||||||
| 9 | 5 | ▶ | use Dancer2::Plugin 0.202000; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 5 | ▶ | use Unicode::Normalize; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | 4 | ▶ | on_plugin_import { | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
| |||||||||||||
| 13 | 4 | my $dsl = shift; | |||||||||||
| 14 | |||||||||||||
| 15 | # pre Plugin2 we need to get settings here | ||||||||||||
| 16 | 4 | my $settings = plugin_setting; | |||||||||||
| 17 | $dsl->app->add_hook( | ||||||||||||
| 18 | Dancer2::Core::Hook->new( | ||||||||||||
| 19 | name => 'before', | ||||||||||||
| 20 | 11 | ▶ | code => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=12 SCAR=25.8
| |||||||||||||
| 21 | 11 | my $app = shift; | |||||||||||
| 22 | # perhaps better ways to check for Plugin2 but this works | ||||||||||||
| 23 | 11 | ▶ | if ( $dsl->can('execute_plugin_hook')) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 24 | # Plugin2 - fetch fresh config on each run | ||||||||||||
| 25 | 11 | $settings = plugin_setting; | |||||||||||
| 26 | } | ||||||||||||
| 27 | 0 | ▶ | for (@{$settings->{'exclude'}}) { return if $app->request->path =~ /$_/ } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 28 | |||||||||||||
| 29 | 11 | ▶ | my $form = $settings->{'form'} || 'NFC'; | ||||||||||
|
Condition100%2/2
$settings->{'form'} || 'NFC'
MC/DC100%1/1
$settings->{'form'} || 'NFC'
$settings->{'form'}
Truth table100%2/2
A
A= $settings->{'form'}
| |||||||||||||
| 30 | 11 | my $normalizer = Unicode::Normalize->can($form); | |||||||||||
| 31 | |||||||||||||
| 32 | 11 | ▶ | unless ($normalizer) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 33 | 0 | require Carp; | |||||||||||
| 34 | 0 | Carp::croak( "Invalid normalization form '$form' requested" ); | |||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | 11 | for (qw/query body route/) { | |||||||||||
| 38 | 33 | my $p = $app->request->params($_); | |||||||||||
| 39 | 33 | ▶ | next unless $p; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 40 | 23 | %{$p} = map { $_ => $normalizer->($p->{$_}) } grep { $p->{$_} } keys %{$p}; | |||||||||||
| 41 | } | ||||||||||||
| 42 | 11 | $app->request->_build_params; | |||||||||||
| 43 | |||||||||||||
| 44 | 11 | ▶ | if ( $app->request->can("body_parameters") ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 45 | 11 | for (qw/query_parameters body_parameters route_parameters/) { | |||||||||||
| 46 | 33 | my $p = $app->request->$_; | |||||||||||
| 47 | 33 | for my $key ( $p->keys ) { | |||||||||||
| 48 | 15 | ▶ | $p->set( $key, map { $_ ? $normalizer->($_) : $_} $p->get_all($key) ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 49 | } | ||||||||||||
| 50 | } | ||||||||||||
| 51 | } | ||||||||||||
| 52 | }, | ||||||||||||
| 53 | 4 | ), | |||||||||||
| 54 | ); | ||||||||||||
| 55 | 5 | }; | |||||||||||
| 56 | |||||||||||||
| 57 | 5 | register_plugin for_versions => [2]; | |||||||||||
| 58 | |||||||||||||
| 59 | 5 | 1; | |||||||||||
| 60 | |||||||||||||
| 61 | __END__ | ||||||||||||