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