| 1 | #!/usr/local/bin/perl | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use Config::Any; | ||
| 5 | use Data::Dumper (); | ||
| 6 | use Regexp::Assemble; | ||
| 7 | |||
| 8 | our $VERSION = '2.05'; # VERSION | ||
| 9 | |||
| 10 | if ( @ARGV == 1 && $ARGV[0] =~ /\A --? h(?:elp)? \z/ix) { | ||
| 11 | help(); | ||
| 12 | exit; | ||
| 13 | } | ||
| 14 | |||
| 15 | if ( @ARGV == 1 ) { | ||
| 16 | my $file = $ARGV[0]; | ||
| 17 | |||
| 18 | # do we have a filename or stem? | ||
| 19 | my $regex_builder = Regexp::Assemble->new; | ||
| 20 | |||
| 21 | map { $regex_builder->add($_) } Config::Any->extensions; | ||
| 22 | |||
| 23 | my $regex = $regex_builder->re; | ||
| 24 | my $config; | ||
| 25 | |||
| 26 | if ( $file =~ m/ \. $regex \z /x ) { | ||
| 27 | $config = Config::Any->load_files({ | ||
| 28 | files => [$file], | ||
| 29 | _config_any_args(), | ||
| 30 | }); | ||
| 31 | } | ||
| 32 | else { | ||
| 33 | $config = Config::Any->load_stems({ | ||
| 34 | stems => [$file], | ||
| 35 | _config_any_args(), | ||
| 36 | }); | ||
| 37 | } | ||
| 38 | |||
| 39 | die "File not found: '$file'\n" | ||
| 40 | if !@$config; | ||
| 41 | |||
| 42 | my ( $filename, $data ) = %{ $config->[0] }; | ||
| 43 | |||
| 44 | my $dumper = Data::Dumper->new( [$data] ); | ||
| 45 | |||
| 46 | $dumper->Terse(1); | ||
| 47 | $dumper->Useqq(1); | ||
| 48 | $dumper->Quotekeys(0); | ||
| 49 | $dumper->Sortkeys(1); | ||
| 50 | |||
| 51 | print "$filename\n"; | ||
| 52 | print $dumper->Dump; | ||
| 53 | } | ||
| 54 | else { | ||
| 55 | die <<ERROR; | ||
| 56 | html_formfu_dumpconf.pl: requires a single filename argument. | ||
| 57 | Try "--help" for help. | ||
| 58 | ERROR | ||
| 59 | } | ||
| 60 | |||
| 61 | sub _config_any_args { | ||
| 62 | return ( | ||
| 63 | use_ext => 1, | ||
| 64 | ); | ||
| 65 | } | ||
| 66 | |||
| 67 | sub help { | ||
| 68 | print <<'HELP'; | ||
| 69 | html_formfu_dumpconf.pl file.conf | ||
| 70 | |||
| 71 | html_formfu_dumpconf.pl file # searches for any supported file extensions | ||
| 72 | |||
| 73 | html_formfu_dumpconf.pl --help | ||
| 74 | |||
| 75 | =head1 DESCRIPTION | ||
| 76 | |||
| 77 | Uses Config::Any and Data::Dumper to display how your config file is parsed. | ||
| 78 | HELP | ||
| 79 | } | ||
| 80 | |||
| 81 | __END__ | ||
| 82 | |||
| 83 | =head1 NAME | ||
| 84 | |||
| 85 | html_formfu_dumpconf.pl - dump configuration files | ||
| 86 | |||
| 87 | =head1 VERSION | ||
| 88 | |||
| 89 | version 2.05 | ||
| 90 | |||
| 91 | =head1 SYNOPSIS | ||
| 92 | |||
| 93 | html_formfu_dumpconf.pl F<file.conf> | ||
| 94 | |||
| 95 | html_formfu_dumpconf.pl F<file> | ||
| 96 | |||
| 97 | =head1 DESCRIPTION | ||
| 98 | |||
| 99 | Uses Config::Any and Data::Dumper to display how your config file is parsed. | ||
| 100 | |||
| 101 | =head1 SEE ALSO | ||
| 102 | |||
| 103 | Config::Any, Data::Dumper |