File Coverage

blib/lib/Dancer2/ConfigUtils.pm
Criterion Covered Total %
statement 18 18 100.0
branch 2 2 100.0
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 26 27 96.3


line stmt bran cond sub pod time code
1             package Dancer2::ConfigUtils;
2             # ABSTRACT: Config utility helpers
3             $Dancer2::ConfigUtils::VERSION = '2.1.0';
4 167     167   489265 use strict;
  167         538  
  167         7267  
5 167     167   938 use warnings;
  167         360  
  167         12763  
6              
7 167     167   1135 use Carp;
  167         351  
  167         17600  
8 167     167   2386 use Module::Runtime qw{ require_module };
  167         5406  
  167         1568  
9              
10 167     167   12234 use Exporter 'import';
  167         1773  
  167         47128  
11             our @EXPORT_OK = qw(
12             normalize_config_entry
13             );
14              
15             my $NORMALIZERS = {
16             charset => sub {
17             my ($charset) = @_;
18             return $charset if !length( $charset || '' );
19              
20             require_module('Encode');
21             my $encoding = Encode::find_encoding($charset);
22             croak
23             "Charset defined in configuration is wrong : couldn't identify '$charset'"
24             unless defined $encoding;
25             my $name = $encoding->name;
26              
27             # Perl makes a distinction between the usual perl utf8, and the strict
28             # utf8 charset. But we don't want to make this distinction
29             $name = 'utf-8' if $name eq 'utf-8-strict';
30             return $name;
31             },
32             };
33              
34             sub normalize_config_entry {
35 3286     3286 0 407744 my ( $name, $value ) = @_;
36             $value = $NORMALIZERS->{$name}->($value)
37 3286 100       8446 if exists $NORMALIZERS->{$name};
38 3284         13086 return $value;
39             }
40              
41             1;
42              
43             __END__