Config-General-Hierarchical

 view release on metacpan or  search on metacpan

Hierarchical/Dump.pm  view on Meta::CPAN

    my $ret = '[';

    foreach my $val (@$value) {
        $val =~ s/\n/\\n/g;
        $ret .= "\"$val\",";
    }

    chop $ret;

    return $ret . '],';
}

sub translate_value {
    my ( $name, $value, $file ) = @_;

    unless ( ref $value ) {
        return [ $name, "'$value';", $file ] if $value !~ /\n/;

        my $return = [ $name, '<<EOF;', $file ];

        return ( $return, $value . "EOF\n" ) if $value =~ /\n$/;

        return ( $return, $value . "//--new line added\nEOF\n" );
    }

    my @ret;
    my $simple = 1;

    foreach my $val (@$value) {
        $simple = 0 if $val =~ /\n/;
    }

    return [ $name, "( '" . join( "', '", @$value ) . "' );", $file ]
      if $simple;

    return ( [ $name, '*;', $file ],
        "* = ( '" . join( "', '", @$value ) . "' );\n" );
}

1;

__END__

=head1 NAME

Config::General::Hierarchical::Dump - Hierarchical Generic Config Dumper Module

=head1 SYNOPSIS

Simple use:

 $
 $ cat example.conf
 #!/usr/local/bin/perl -MConfig::General::Hierarchical::Dump
 variable1 value
 variable2
 <node>
  key value
 </node>
 $
 $ chmod 755 example.conf
 $ ./example.conf
 node->key = 'value'
 variable1 = 'value'
 variable2 = ''
 $
 $

Full use:

 package MyConfig::Dump;
 #
 use base 'Config::General::Hierarchical::Dump';
 use MyConfig;
 #
 sub parser {
  return 'MyConfig';
 }

=head1 DESCRIPTION

This module provides an easy way to dump configuration files written for
L<Config::General::Hierarchical>.

=head1 SUBROUTINES/METHODS

=over

=item import

Implicitally called by B<-M> perl option, it reads the configuration file itself, dumps
it to I<standard output> and exits.

=item parser

Returns the class name to be used to parse the file, by default
C<Config::General::Hierarchical>. If you exetend C<Config::General::Hierarchical> with
so many customization that you need to use your own class to parse the file, you can
extend C<Config::General::Hierarchical::Dump> as well and simply redefine this method
to return your own class name and use this second new class as parameter of B<-M> perl
option.

=back

=head1 CMD LINE PARAMETERS

=over

=item -c, --check

This can beusefull to find immediatelly which are eventaul B<configuration variables> not
respecting the B<syntax constraint>

=item -f, --file

Makes the source file (foreach variable) to be printed.

=item -l, --fixed-length

Formats the output as fixed characters length.



( run in 1.500 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )