package ties;

use warnings;
use strict;

use File::Slurp;
use Data::Dump qw/dump/;

#use server;

sub TIESCALAR {
	my ($class,$name,$default) = @_;

#	my $path = $server::base_dir . '/conf/' . $name; # FIXME we can't call server because it require this package
	my $path = "/srv/pxelator/conf/$name";

	my $o = {
		path => $path,
	};
	write_file $o->{path}, $default unless -f $o->{path};

	warn "# TIESCALAR $name ", $o->{path}, " [$default]";

	bless \$o,$class;
}

sub STORE {
	my ( $self, $value ) = @_;
	write_file $$self->{path}, $value;
}

sub FETCH {
	my $self = shift;
	my $v = read_file $$self->{path};
	chomp($v);
	$v;
}

1;
