/
Simple.pm6
38 lines (33 loc) · 837 Bytes
/
Simple.pm6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use Config::Simple::Role;
use Data::Dump;
use MONKEY-SEE-NO-EVAL;
class Config::Simple does Config::Simple::Role {
method read($filename, Str :$f) {
my $this;
if ($f) {
my $module = "Config::Simple::$f";
require ::($module);
$this = ::($module).new();
$this.read($filename);
} else {
my $text = slurp($filename);
$this = self.bless(:filename($filename), :hash(EVAL($text)));
}
return $this;
}
method new(Str :$f) {
if ($f) {
my $module = "Config::Simple::$f";
require ::($module);
return ::($module).new();
}
return self.bless();
}
method write($filename = Any) {
$.filename = $filename if $filename.defined;
my $fh = open $.filename, :w;
$fh.print(Dump(%(%!hash), :color(False)));
$fh.print("\n");
$fh.close;
}
}