blib/lib/Bot/Cobalt/Frontend/RC.pm

filter: Statementstmt 43.7% 21 / 48 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 58.3% 7 / 12 Podpod 100% 2 / 2 totaltotal 30.6% 30 / 98 SCAR 41.9
CC
12
Cov
28%
rc_read
72.0
rc_write
30.0
__ANON__
2.0
CRAP 65.7
« blib/lib/Bot/Cobalt/Core/Role/IRC.pm ↑ Summary blib/lib/Bot/Cobalt/Utils.pm »
1 package Bot::Cobalt::Frontend::RC;
2 $Bot::Cobalt::Frontend::RC::VERSION = '0.021002';
3 2 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use Bot::Cobalt::Serializer;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use parent 'Exporter::Tiny';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 our @EXPORT_OK = qw/
17 rc_read
18 rc_write
19 /;
20  
21 sub rc_read {
22 0 ▶ my ($rcfile) = @_;
Subroutine rc_read: not called CC=8 SCAR=42.8
Pod documented
23 0 ▶ croak "rc_read needs a rcfile path" unless $rcfile;
Branch: 1 branch
BranchTrueFalseTotal
unless $rcfile 0 0 0
24  
25 my $generic_crappy_err = sub {
26 0 ▶ warn
Subroutine __ANON__: not called CC=1 SCAR=6.9
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 0 };
32  
33 0 my $rc_err;
34 my $rc_h = try {
35 0 ▶ Bot::Cobalt::Serializer->new->readfile($rcfile)
Subroutine __ANON__: not called CC=1 SCAR=6.9
36 } catch {
37 0 ▶ $generic_crappy_err->();
Subroutine __ANON__: not called CC=1 SCAR=6.9
38 0 $rc_err = $_;
39 undef
40 0 ▶ } or croak "Could not rc_read(); readfile said $rc_err";
Branch: 1 branch
BranchTrueFalseTotal
my $rc_h = &try(sub { "Bot::Cobalt::Serializer"->new->readfile($rcfile); } , &catch(sub { &$generic_crappy_err(); $rc_err = $_; undef; } )) or croak("Could not rc_read(); readfile said $rc_err") 0 0 0
41
42 0 ▶ unless ($rc_h && ref $rc_h eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rc_h and ref $rc_h eq "HASH") 0 0 0
Condition0%0/3
$rc_h and ref $rc_h eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$rc_h and ref $rc_h eq "HASH"
$rc_h ref $rc_h eq "HASH"
Truth table0%0/3
A and B
A= $rc_hB= ref $rc_h eq "HASH"
ABresult
0X0
100
111
43 0 $generic_crappy_err->();
44 0 croak "rc_read ($rcfile) expected to receive a hash"
45 }
46  
47 0 my ($BASE, $ETC, $VAR) = @$rc_h{'BASE', 'ETC', 'VAR'};
48
49 0 ▶ unless ($BASE && $ETC && $VAR) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($BASE and $ETC and $VAR) 0 0 0
Condition0%0/6
$BASE and $ETC and $VAR
!ll&&!rl&&r
000
$BASE and $ETC
!ll&&!rl&&r
000
MC/DC0%0/3
$BASE and $ETC and $VAR
$BASE $ETC $VAR
Truth table0%0/4
A and B and C
A= $BASEB= $ETCC= $VAR
ABCresult
0XX0
10X0
1100
1111
50 0 warn "rc_read; could not find BASE, ETC, VAR\n";
51 0 warn "BASE: $BASE\nETC: $ETC\nVAR: $VAR\n";
52 0 croak "Cannot continue without a valid rcfile"
53 }
54
55 0 return ($BASE, $ETC, $VAR)
56 }
57  
58 sub rc_write {
59 0 ▶ my ($rcfile, $basepath) = @_;
Subroutine rc_write: not called CC=5 SCAR=34.0
Pod documented
60 0 ▶ croak "rc_write needs rc file path and base directory path"
Branch: 1 branch
BranchTrueFalseTotal
unless $rcfile and $basepath 0 0 0
Condition0%0/3
$rcfile and $basepath
!ll&&!rl&&r
000
MC/DC0%0/2
$rcfile and $basepath
$rcfile $basepath
Truth table0%0/3
A and B
A= $rcfileB= $basepath
ABresult
0X0
100
111
61 unless $rcfile and $basepath;
62  
63 0 ▶ unless ( File::Spec->file_name_is_absolute($basepath) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("File::Spec"->file_name_is_absolute($basepath)) 0 0 0
64 0 ▶ my $homedir = $ENV{HOME} || Cwd::cwd();
Condition0%0/3
$ENV{'HOME'} || Cwd::cwd()
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'HOME'} || Cwd::cwd()
$ENV{'HOME'} Cwd::cwd()
Truth table0%0/3
A || B
A= $ENV{'HOME'}B= Cwd::cwd()
ABresult
1X1
011
000
65 0 $basepath = File::Spec->catdir( $homedir, $basepath );
66 }
67  
68 0 my $rc_h = {
69 BASE => $basepath,
70 ETC => File::Spec->catdir( $basepath, 'etc' ),
71 VAR => File::Spec->catdir( $basepath, 'var' ),
72 };
73  
74 0 Bot::Cobalt::Serializer->new->writefile(
75 $rcfile, $rc_h
76 );
77  
78 0 $basepath
79 }
80  
81 1;
82 __END__
« blib/lib/Bot/Cobalt/Core/Role/IRC.pm ↑ Summary blib/lib/Bot/Cobalt/Utils.pm »