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.0.1';
4 162     162   424841 use strict;
  162         446  
  162         7273  
5 162     162   929 use warnings;
  162         362  
  162         11924  
6              
7 162     162   1035 use Carp;
  162         320  
  162         14849  
8 162     162   2166 use Module::Runtime qw{ require_module };
  162         4416  
  162         1678  
9              
10 162     162   9478 use Exporter 'import';
  162         390  
  162         43677  
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 2657     2657 0 274003 my ( $name, $value ) = @_;
36             $value = $NORMALIZERS->{$name}->($value)
37 2657 100       6774 if exists $NORMALIZERS->{$name};
38 2656         7218 return $value;
39             }
40              
41             1;
42              
43             __END__