Oleg G

NAME

JCONF::Writer - Create JCONF configuration from perl code

SYNOPSIS

        use strict;
        use JCONF::Writer;
        use JCONF::Writer::Boolean qw(TRUE FALSE);
        
        my $writer = JCONF::Writer->new(autodie => 1);
        my %cfg = (
                modules => {
                        Moose => 1,
                        Mouse => 0.91,
                        Moo   => 0.05,
                        Mo    => [0.01, 0.08],
                },
         
                enabled => TRUE,
                data    => ["Test data", "Production data"]
         
                query   => q!SELECT * from pkg
                                   LEFT JOIN ver ON pkg.id=ver.pkg_id
                                   WHERE pkg.name IN ("Moose", "Mouse", "Moo", "Mo")!
        );
        
        my $jconf = eval {
                $writer->from_hashref(\%cfg);
        };
        if ($@) {
                die "Invalid config: ", $@;
        }
        
        print $jconf;
        
        __END__
        modules = {
                Moose: 1,
                Mouse: 0.91,
                Moo: 0.05,
                Mo: [0.01, 0.08],
        }
         
        enabled = true
        data = ["Test data", "Production data"]
         
        query = "SELECT * from pkg
                         LEFT JOIN ver ON pkg.id=ver.pkg_id
                         WHERE pkg.name IN (\"Moose\", \"Mouse\", \"Moo\", \"Mo\")"

METHODS

new

This is writer object constructor. Available parameters are:

autodie

throw exception on any error if true, default is false (in this case writer methods will return undef on error and error may be found with "last_error" method)

from_hashref

Converts hash reference to valid formatted JCONF and returns it as string. On fail returns undef/throws exception (according to autodie option in the constructor).

last_error

Returns error occured for last writer call. Error will be JCONF::Writer::Error object or undef (if there was no error).

SEE ALSO

Parse::JCONF

COPYRIGHT

Copyright Oleg G <oleg@cpan.org>.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.