Config-Resolver

 view release on metacpan or  search on metacpan

lib/Config/Resolver.pm  view on Meta::CPAN

  return $result;
}

########################################################################
sub is_key_or_idx {
########################################################################
  my ($p) = @_;

  my ( $key, $idx );

  # array?
  if ( $p =~ /^([ _[:alpha:][:digit:]]+)\[(\d+)\]$/ixsm ) {
    $key = $1;
    $idx = $2;
  }
  # hash key?
  elsif ( $p =~ /^([ _[:alpha:][:digit:]]+)/ixsm ) {
    $key = $1;
  }

  return ( $key, $idx );
}

1;

__END__

=pod

=head1 NAME

Config::Resolver - Recursively resolve placeholders in a data structure

=head1 SYNOPSIS

 use Config::Resolver;

 # 1. Base use (default, safe functions)
 my $resolver = Config::Resolver->new();
 my $config = $resolver->resolve(
     '${uc(greeting)}', { greeting => 'hello' }
 );
 # $config is now 'HELLO'

 # 2. Extended use (injecting a custom "allowed" function)
 my $resolver_ext = Config::Resolver->new(
     functions => {
         'reverse' => sub { return scalar reverse( $_[0] // '' ) },
     }
 );
 my $config_ext = $resolver_ext->resolve(
     '${reverse(greeting)}', { greeting => 'hello' }
 );
 # $config_ext is now 'olleh'
 
 # 3. Pluggable Backends (for ssm://, vault://, etc.)
 
 # A) Dynamically load installed plugins...

 my $my_plugin_config = {
     'ssm' => { 'endpoint_url' => 'http://localhost:4566' }
 };

 my $resolver_plugins = Config::Resolver->new(
     plugins       => [ 'SSM' ],
     plugin_config => $my_plugin_config,
 );
 
 my $ssm_val = $resolver_plugins->resolve('ssm://my/ssm/path');

 # B) Manual "shim" injection
 my $resolver_manual = Config::Resolver->new(
     backends => {
         'my_db' => sub {
             my ($path, $parameters) = @_;
             # ... logic to resolve $path using $parameters ...
             return "value_for_${path}";
         }
     }
 );

 my $db_val = $resolver_manual->resolve('my_db://foo');
 # $db_val is now 'value_for_foo'

=head1 DESCRIPTION

C<Config::Resolver> is a powerful and extensible engine for dynamically
resolving placeholders in complex data structures.

While this module can be used directly in any Perl application
(see L<SYNOPSIS>), it is primarily designed as the engine for the
L<config-resolver.pl> command-line utility .

The C<config-resolver.pl> harness provides a complete, robust, and
testable solution for managing configuration files. It is intended to
replace complex and brittle C<sed>, C<awk>, or C<envsubst> logic
in deployment scripts, such as those found in `docker-entrypoint.sh`
scripts or CI/CD pipelines.

This class allows you to define a configuration that contains
placeholders that can be resolved from multiple sources.

=over 5

=item From a hash reference 

=item By a safe, "allowed-list" function call 

=item By pluggable, protocol-based backends (e.g., C<ssm://>) 

=back

=head1 FEATURES

The C<Config::Resolver> engine (and its harness) are built to
solve common, real-world DevOps and configuration challenges.

=over 4

=item * B<Command-Line Harness>



( run in 1.896 second using v1.01-cache-2.11-cpan-d8267643d1d )