| 1 | 5 | ▶ | use v5.26; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | 5 | ▶ | use Object::Pad; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | |||
| 4 | 5 | ▶ | use Getopt::Pad::Config::Format; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | class Getopt::Pad::Config::Format::Yaml :isa(Getopt::Pad::Config::Format) :strict(params) { | ||
| 7 | 5 | ▶ | use Encode (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 5 | ▶ | use Feature::Compat::Try; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 5 | ▶ | use Getopt::Pad::Util qw(specError); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | 5 | our $VERSION = '0.04'; | |
| 12 | |||
| 13 | 5 | ▶ | use constant NAMES => ['yaml', 'yml']; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | |||
| 15 | # A missing YAML::XS is an installation problem for the programmer: | ||
| 16 | # report it when the spec is built, not when the first file is read. | ||
| 17 | ADJUST { | ||
| 18 | try { require YAML::XS } | ||
| 19 | catch ($error) { specError("config format 'yaml' requires the YAML::XS module") } | ||
| 20 | } | ||
| 21 | |||
| 22 | # YAML::XS speaks UTF-8 octets on both sides while the Format seam | ||
| 23 | # speaks text, so the translation happens here and nowhere else. | ||
| 24 | 44 | ▶ | method parse($text) { |
|
Subroutine
parse: called CC=1 SCAR=0.0
Pod
documented
| |||
| 25 | # A config file is data: a !!perl/... tag never blesses anything, | ||
| 26 | # whatever the installed YAML::XS defaults to. | ||
| 27 | 44 | local $YAML::XS::LoadBlessed = 0; | |
| 28 | 44 | return YAML::XS::Load(Encode::encode('UTF-8', $text)); | |
| 29 | 5 | } | |
| 30 | |||
| 31 | 4 | ▶ | method dump($data) { |
|
Subroutine
dump: called CC=1 SCAR=0.0
Pod
documented
| |||
| 32 | 4 | return Encode::decode('UTF-8', YAML::XS::Dump($data)); | |
| 33 | 5 | } | |
| 34 | } | ||
| 35 | |||
| 36 | 5 | 1; | |
| 37 | |||
| 38 | __END__ | ||