line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bot::Cobalt::Frontend::RC; |
2
|
|
|
|
|
|
|
$Bot::Cobalt::Frontend::RC::VERSION = '0.021003'; |
3
|
1
|
|
|
1
|
|
901
|
use strictures 2; |
|
1
|
|
|
|
|
1174
|
|
|
1
|
|
|
|
|
37
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
143
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
51
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use Cwd (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
11
|
|
8
|
1
|
|
|
1
|
|
3
|
use File::Spec (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
11
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
403
|
use Try::Tiny; |
|
1
|
|
|
|
|
1567
|
|
|
1
|
|
|
|
|
45
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
359
|
use Bot::Cobalt::Serializer; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
45
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
11
|
use parent 'Exporter::Tiny'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT_OK = qw/ |
17
|
|
|
|
|
|
|
rc_read |
18
|
|
|
|
|
|
|
rc_write |
19
|
|
|
|
|
|
|
/; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub rc_read { |
22
|
1
|
|
|
1
|
1
|
1
|
my ($rcfile) = @_; |
23
|
1
|
50
|
|
|
|
4
|
croak "rc_read needs a rcfile path" unless $rcfile; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $generic_crappy_err = sub { |
26
|
0
|
|
|
0
|
|
0
|
warn |
27
|
|
|
|
|
|
|
"Errors reported during rcfile parse\n", |
28
|
|
|
|
|
|
|
"You may have an old, incompatible, or broken rcfile.\n", |
29
|
|
|
|
|
|
|
"Path: $rcfile\n", |
30
|
|
|
|
|
|
|
"Try running cobalt2-installer\n" ; |
31
|
1
|
|
|
|
|
4
|
}; |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
1
|
my $rc_err; |
34
|
|
|
|
|
|
|
my $rc_h = try { |
35
|
1
|
|
|
1
|
|
59
|
Bot::Cobalt::Serializer->new->readfile($rcfile) |
36
|
|
|
|
|
|
|
} catch { |
37
|
0
|
|
|
0
|
|
0
|
$generic_crappy_err->(); |
38
|
0
|
|
|
|
|
0
|
$rc_err = $_; |
39
|
|
|
|
|
|
|
undef |
40
|
1
|
50
|
|
|
|
6
|
} or croak "Could not rc_read(); readfile said $rc_err"; |
|
0
|
|
|
|
|
0
|
|
41
|
|
|
|
|
|
|
|
42
|
1
|
50
|
33
|
|
|
40
|
unless ($rc_h && ref $rc_h eq 'HASH') { |
43
|
0
|
|
|
|
|
0
|
$generic_crappy_err->(); |
44
|
0
|
|
|
|
|
0
|
croak "rc_read ($rcfile) expected to receive a hash" |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
2
|
my ($BASE, $ETC, $VAR) = @$rc_h{'BASE', 'ETC', 'VAR'}; |
48
|
|
|
|
|
|
|
|
49
|
1
|
50
|
33
|
|
|
6
|
unless ($BASE && $ETC && $VAR) { |
|
|
|
33
|
|
|
|
|
50
|
0
|
|
|
|
|
0
|
warn "rc_read; could not find BASE, ETC, VAR\n"; |
51
|
0
|
|
|
|
|
0
|
warn "BASE: $BASE\nETC: $ETC\nVAR: $VAR\n"; |
52
|
0
|
|
|
|
|
0
|
croak "Cannot continue without a valid rcfile" |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
|
|
7
|
return ($BASE, $ETC, $VAR) |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub rc_write { |
59
|
1
|
|
|
1
|
1
|
2384
|
my ($rcfile, $basepath) = @_; |
60
|
1
|
50
|
33
|
|
|
9
|
croak "rc_write needs rc file path and base directory path" |
61
|
|
|
|
|
|
|
unless $rcfile and $basepath; |
62
|
|
|
|
|
|
|
|
63
|
1
|
50
|
|
|
|
7
|
unless ( File::Spec->file_name_is_absolute($basepath) ) { |
64
|
0
|
|
0
|
|
|
0
|
my $homedir = $ENV{HOME} || Cwd::cwd(); |
65
|
0
|
|
|
|
|
0
|
$basepath = File::Spec->catdir( $homedir, $basepath ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
9
|
my $rc_h = { |
69
|
|
|
|
|
|
|
BASE => $basepath, |
70
|
|
|
|
|
|
|
ETC => File::Spec->catdir( $basepath, 'etc' ), |
71
|
|
|
|
|
|
|
VAR => File::Spec->catdir( $basepath, 'var' ), |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
6
|
Bot::Cobalt::Serializer->new->writefile( |
75
|
|
|
|
|
|
|
$rcfile, $rc_h |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
|
78
|
1
|
|
|
|
|
11
|
$basepath |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
82
|
|
|
|
|
|
|
__END__ |