/usr/share/doc/libconfig-merge-perl/examples/browser.pl is in libconfig-merge-perl 1.04-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | #!/usr/bin/perl
use strict;
use warnings;
use blib;
use Config::Merge();
use File::Spec();
init();
my $debug = shift @ARGV;
my $prod = Config::Merge->new( path => get_path('config_prod') , debug => $debug);
my $dev = Config::Merge->new( path => get_path('config_dev') , debug => $debug);
my $term = Term::ReadLine->new('Browser');
while ( defined( my $path = $term->readline("Enter path:") ) ) {
last if $path eq 'q';
$term->addhistory($path);
print "\n";
dump_vals( 'Production Config', $prod, $path );
dump_vals( 'Dev Config', $dev, $path );
}
#===================================
sub dump_vals {
#===================================
my ( $title, $config, $path ) = @_;
print "$title\n" . ( '-' x length($title) ) . "\n ";
my $vals = eval { scalar $config->($path) };
if ($@) {
print " -- PATH NOT FOUND --";
}
else {
if ( my $ref = ref $vals ) {
if ( $ref eq 'ARRAY' ) {
print "ARRAY: " . join( ', ', @$vals );
}
elsif ( $ref eq 'HASH' ) {
print "HASH KEYS: " . join( ', ', keys %$vals );
}
else {
print "$ref";
}
}
else {
print "SCALAR: $vals";
}
}
print "\n\n";
}
#===================================
sub get_path {
#===================================
my ($vol,$path) = File::Spec->splitpath(
File::Spec->rel2abs($0)
);
$path = File::Spec->catdir(
File::Spec->splitdir($path),
,@_
);
return File::Spec->catpath($vol,$path,'');
}
#===================================
sub init {
#===================================
print <<USAGE;
This browser allows you to compare an example configuration tree
for production and development environments. The only difference is
that development has a 'local.yaml' file.
Type in the path of the value you would like to see, eg: app.images.path
Try just pressing Enter to start.
'q' to quit
USAGE
eval { require Term::ReadLine }
or die "ERROR: "
. "Term::ReadLine needs to be installed to use this example browser\n\n";
eval { require YAML::Syck }
or eval { require YAML }
or die "ERROR: "
. "YAML::Syck or YAML needs to be installed to use this example browser\n\n"
;
}
|