blib/lib/Dancer2/Plugin/UnicodeNormalize.pm

filter: Statementstmt 93.4% 43 / 46 Branchbran 58.3% 7 / 12 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 88.0% 59 / 67 CC 12 SCAR 22.6
CC
12
Cov
87%
__ANON__
13.2
__ANON__
1.0
BEGIN
1.0
CRAP 9.6
↑ Summary
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
BranchTrueFalseTotal
if ($dsl->can("execute_plugin_hook")) 11 0 11
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
BranchTrueFalseTotal
if $app->request->path =~ /$_/ 0 0 0
28  
29 11 ▶ my $form = $settings->{'form'} || 'NFC';
Condition100%2/2
$settings->{'form'} || 'NFC'
l!l
47
MC/DC100%1/1
$settings->{'form'} || 'NFC'
$settings->{'form'}
Truth table100%2/2
A
A= $settings->{'form'}
Aresult
11
00
30 11 my $normalizer = Unicode::Normalize->can($form);
31  
32 11 ▶ unless ($normalizer) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($normalizer) 0 11 11
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
BranchTrueFalseTotal
unless $p 10 23 33
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
BranchTrueFalseTotal
if ($app->request->can("body_parameters")) 11 0 11
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
BranchTrueFalseTotal
$_ ? : 14 1 15
49 }
50 }
51 }
52 },
53 4 ),
54 );
55 5 };
56  
57 5 register_plugin for_versions => [2];
58  
59 5 1;
60  
61 __END__
↑ Summary