Config-Trivial

 view release on metacpan or  search on metacpan

lib/Config/Trivial.pm  view on Meta::CPAN

#

sub new {
    my $class  = shift;
    my %args   = @_;
    my $object = bless {
        _config_file   => $_file,       # The Config file, default is caller
        _self          => 1,            # Set Self Read
        _error_message => q{},          # Error Messages
        _configuration => {},           # Where the configuration data goes
        _backup_char   => q{~},         # Backup marker
        _separator     => q{ },         # Separator
        _multi_file    => 0,            # Multi file mode
        _debug    => $args{debug}    || 0, # Debugging (verbose) mode
        _strict   => $args{strict}   || 0, # Strict mode
        _no_check => $args{no_check} || 0, # Skip filesystem checks
        },
        ref $class || $class;

    if ( $args{config_file} ) {
        croak "Unable to read config file $args{config_file}"

lib/Config/Trivial.pm  view on Meta::CPAN

                'Not allowed to write to the calling file.');
        }
    }
    else {
        croak 'File error: No file name supplied';
    }

    if ( -e $file ) {
        croak "ERROR: Insufficient permissions to write to: $file"
            unless ( -w $file );
        rename $file, $file . $self->{_backup_char}
            or croak "ERROR: Unable to rename $file.";
    }

    open my $config, '>', $file
        or croak "ERROR: Unable to write configuration file: $file";
    print {$config}
        "#\n#\tConfig file written by $_file\n#\tUsing Config::Trivial version $VERSION\n#\n\n";

    foreach my $setting ( keys %{$settings} ) {
        if ( $setting =~ / / ) {                    # Check for spaces in keys

t/04-write.t  view on Meta::CPAN

	configuration => $data));					# Write it too
ok(-e "./t/test3.data");

#
#	Read things back (8-15)
#

ok($config = Config::Trivial->new(
    config_file => "./t/test2.data"));          # Create Config object
ok($config->read("test1"), "foo");
ok($config->write);								# write it back (should make a backup)
ok(-e "./t/test2.data~");

ok($config = Config::Trivial->new(
    config_file => "./t/test3.data"));           # Create Config object
ok($config->read("test"), "womble");
ok($config->read('longer_key'), 'muppet');
ok($config->read('silly_key'), 'fraggle');

ok($config->set_configuration($data));



( run in 1.500 second using v1.01-cache-2.11-cpan-49f99fa48dc )