| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | unless ($rc_h && ref $rc_h eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$rc_h and ref $rc_h eq "HASH"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
$BASE and $ETC and $VAR
$BASE and $ETC
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$rcfile and $basepath
MC/DC0%0/2
$rcfile and $basepath
$rcfile
$basepath
Truth table0%0/3
A and B
A= $rcfileB= $basepath
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | unless $rcfile and $basepath; | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | unless ( File::Spec->file_name_is_absolute($basepath) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | my $homedir = $ENV{HOME} || Cwd::cwd(); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$ENV{'HOME'} || Cwd::cwd()
MC/DC0%0/2
$ENV{'HOME'} || Cwd::cwd()
$ENV{'HOME'}
Cwd::cwd()
Truth table0%0/3
A || B
A= $ENV{'HOME'}B= Cwd::cwd()
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||