File: html_formfu_dumpconf.pl

package info (click to toggle)
libhtml-formfu-perl 2.05000-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,328 kB
  • ctags: 831
  • sloc: perl: 12,785; makefile: 9; sql: 5
file content (103 lines) | stat: -rwxr-xr-x 1,881 bytes parent folder | download
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
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/perl
use strict;
use warnings;
use Config::Any;
use Data::Dumper ();
use Regexp::Assemble;

our $VERSION = '2.05'; # VERSION

if ( @ARGV == 1 && $ARGV[0] =~ /\A --? h(?:elp)? \z/ix) {
    help();
    exit;
}

if ( @ARGV == 1 ) {
    my $file = $ARGV[0];

    # do we have a filename or stem?
    my $regex_builder = Regexp::Assemble->new;

    map { $regex_builder->add($_) } Config::Any->extensions;

    my $regex = $regex_builder->re;
    my $config;

    if ( $file =~ m/ \. $regex \z /x ) {
        $config = Config::Any->load_files({
            files => [$file],
            _config_any_args(),
        });
    }
    else {
        $config = Config::Any->load_stems({
            stems => [$file],
            _config_any_args(),
        });
    }

    die "File not found: '$file'\n"
        if !@$config;

    my ( $filename, $data ) = %{ $config->[0] };

    my $dumper = Data::Dumper->new( [$data] );

    $dumper->Terse(1);
    $dumper->Useqq(1);
    $dumper->Quotekeys(0);
    $dumper->Sortkeys(1);

    print "$filename\n";
    print $dumper->Dump;
}
else {
    die <<ERROR;
html_formfu_dumpconf.pl: requires a single filename argument.
Try "--help" for help.
ERROR
}

sub _config_any_args {
    return (
        use_ext => 1,
    );
}

sub help {
    print <<'HELP';
html_formfu_dumpconf.pl file.conf

html_formfu_dumpconf.pl file # searches for any supported file extensions

html_formfu_dumpconf.pl --help

=head1 DESCRIPTION

Uses Config::Any and Data::Dumper to display how your config file is parsed.
HELP
}

__END__

=head1 NAME

html_formfu_dumpconf.pl - dump configuration files

=head1 VERSION

version 2.05

=head1 SYNOPSIS

    html_formfu_dumpconf.pl F<file.conf>

    html_formfu_dumpconf.pl F<file>

=head1 DESCRIPTION

Uses Config::Any and Data::Dumper to display how your config file is parsed.

=head1 SEE ALSO

Config::Any, Data::Dumper