Config-Writer

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

        relative path part. Path part handling is described in **workdir** option description below.

        New temporary file will be created on success and all write operations will be performed
        on this temporary file. On **close()** method invocation existing configuration file can
        be moved to a backup file (see descrition of **overwrite** option below) and temporary file
        is renamed in place of the original configuration file.

    - **format** = STRING

        Configuration file format. Currently unused.

    - **workdir** = STRING

        If filename contains absolute path, work directory is set to a **dirname(1)**
        implicitly regardless of whether **workdir** option is set or not.

        If **workdir** is not set, work directory defaults to **getcwd(3)**.

        If filename contains relative path, it is appended to a work directory name,
        provided either in **workdir** option or returned by **getcwd(3)**.

        Work directory existence check is performed. If work directory does not exist, \`undef\`
        is returned and error flag is set!

    - **retain** = INTEGER

        Quantity of configuration file backups to retain. Default is 0 - do not retain any.

    - **overwrite** = BOOLEAN

        Existing backup file will be either overwritten if the flag is set to true
        (overwrite = 1) or stayed untouched (overwrite = 0). E. g. if you choose to
        store single backup per day, you'll get either the latest configuration version
        before it being updated, or the configuration you've got at the beginning of the
        day.

        Default is 0.

    - **extension** = STRING

        Configuration file backup extension format as described in POSIX strftime function
        documentation. The new extension will replace original one, so the backup files
        should not be loaded even in case wildcards (e. g. '**\*.conf**') are used to include
        configuration from a several files. Existing backup files will either stay untouched
        or overwritten depending on **overwrite** flag value.

        Default is '-%Y-%m-%d'.

    - **owner** = STRING

        Configuration file owner name. If file owner can not be changed, error flag is set.

        Defaults to process EUID.

    - **group** = STRING

        Configuration file group name. If not provided, process EGID is used.

    - **permissions** = OCTAL

        Configuration file permissions in numeric format. Read **chmod(1)** manual for
        details.

        Default is 0600.

- **error()**

    Takes no arguments. Returns \`false\` if **Config::Writer** object is
    defined and \`error\` flag is not set and \`true\` otherwise.

- **say(STRING)**

    Is equivalent to **print()** method except that $/ is added to the end of the line.

- **sayf(STRING, ARRAY)**

    Is equivalent to **printf()** method except that $/ is added to the end of the format line.

- **print(STRING)**

    Prints STRING to temporary file as is.

- **printf(STRING, ARRAY)**

    Prints formatted string to the temporary file. See **printf(3)** for
    more details.

- **close()**

    When called:

    - closes temporary configuration file;
    - tries to rename target configuration file to a backup file (if \`retain\`
    option is non-zero);
    - tries to remove surplus (oldest) backup files (if \`retain\` option is non-zero); 
    - tries to rename temporary configuration file to a target name.

    If any errors occurs, \`error\` flag is set.

- **fh()**

    Returns a reference to a File::Temp file handle blessed object to be used
    like that:

        use Config::Writer;
        use Template;
        
        my $t = Template->new( ... );
        my $fh = Config::Writer->new( ... );

        $t->process('template.tmpl', { ... }, $fh->fh);
        
        # OR
        
        print { $fh->fh } "Some text\n";

        $fh->close;

### GETTER METHODS

The next methods returns appropriate properties of **Config::Writer**



( run in 1.443 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )