| 1 |
package Dancer2::ConfigUtils; |
| 2 |
# ABSTRACT: Config utility helpers |
| 3 |
$Dancer2::ConfigUtils::VERSION = '2.2.2'; |
| 4 |
use strict; |
| 5 |
use warnings; |
| 6 |
|
| 7 |
use Carp; |
| 8 |
use Module::Runtime qw{ require_module }; |
| 9 |
|
| 10 |
use Exporter 'import'; |
| 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 |
my ( $name, $value ) = @_; |
| 36 |
$value = $NORMALIZERS->{$name}->($value) |
| 37 |
if exists $NORMALIZERS->{$name}; |
| 38 |
return $value; |
| 39 |
} |
| 40 |
|
| 41 |
1; |
| 42 |
|
| 43 |
__END__ |
| 44 |
|
| 45 |
=pod |
| 46 |
|
| 47 |
=encoding UTF-8 |
| 48 |
|
| 49 |
=head1 NAME |
| 50 |
|
| 51 |
Dancer2::ConfigUtils - Config utility helpers |
| 52 |
|
| 53 |
=head1 VERSION |
| 54 |
|
| 55 |
version 2.2.2 |
| 56 |
|
| 57 |
=head1 AUTHOR |
| 58 |
|
| 59 |
Dancer Core Developers |
| 60 |
|
| 61 |
=head1 COPYRIGHT AND LICENSE |
| 62 |
|
| 63 |
This software is copyright (c) 2026 by Alexis Sukrieh. |
| 64 |
|
| 65 |
This is free software; you can redistribute it and/or modify it under |
| 66 |
the same terms as the Perl 5 programming language system itself. |
| 67 |
|
| 68 |
=cut |