Data-Crumbr

 view release on metacpan or  search on metacpan

bin/crumbr  view on Meta::CPAN

sub read_data {
   my ($config, $filename) = @_;
   $filename //= '-';
   my $reader = __PACKAGE__->can("read_data_$config->{type}")
     or die "unsupported input type $config->{type}\n";
   return $reader->($config, $filename);
} ## end sub read_data

sub read_data_yaml {
   my ($config, $filename) = @_;
   my $unicode_string = slurp($filename, $config{encoding});

   for my $class (qw< YAML::XS YAML YAML::Tiny >) {
      eval "use $class";
      next if $EVAL_ERROR;
      my $function = $class->can('Load');
      return $function->($unicode_string);
   } ## end for my $class (qw< YAML::XS YAML YAML::Tiny >)
   die "cannot find any YAML module\n";
   return;
} ## end sub read_data_yaml

sub read_data_json {
   my ($config, $filename) = @_;
   my $unicode_string = slurp($filename, $config{encoding});

   require Encode;
   my $utf8_octets =
     Encode::encode('UTF-8', $unicode_string, Encode::FB_CROAK());

   my @cs = qw< Cpanel::JSON::XS JSON::XS Mojo::JSON JSON::PP >;
   for my $class (@cs) {
      eval "use $class";
      next if $EVAL_ERROR;
      my $function = $class->can('decode_json');
      my $retval = eval { $function->($utf8_octets) };
      die "errors parsing input: $EVAL_ERROR\n"
        if $EVAL_ERROR;
      return $retval;



( run in 0.303 second using v1.01-cache-2.11-cpan-f29a10751f0 )