script/html_formfu_dumpconf.pl untested

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