| 1 | 2 | ▶ | use 5.008; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | package BenchmarkAnything::Config; | ||||||||||||||||||||
| 5 | 2 | ▶ | BEGIN { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | $BenchmarkAnything::Config::AUTHORITY = 'cpan:SCHWIGON'; | |||||||||||||||||||
| 7 | } | ||||||||||||||||||||
| 8 | # ABSTRACT: Read BenchmarkAnything configfile | ||||||||||||||||||||
| 9 | 2 | $BenchmarkAnything::Config::VERSION = '0.003'; | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | sub new | ||||||||||||||||||||
| 12 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 13 | 3 | my $class = shift; | |||||||||||||||||||
| 14 | 3 | my $self = bless { @_ }, $class; | |||||||||||||||||||
| 15 | 3 | $self->_read_config; | |||||||||||||||||||
| 16 | 3 | return $self; | |||||||||||||||||||
| 17 | } | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | sub _read_config | ||||||||||||||||||||
| 21 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
_read_config: called CC=7 SCAR=20.0
| |||||||||||||||||||||
| 22 | 3 | my ($self) = @_; | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 3 | require File::HomeDir; | |||||||||||||||||||
| 25 | 3 | require YAML::Any; | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | # don't look into user's homedir if we are running tests | ||||||||||||||||||||
| 28 | 3 | ▶ | my $default_cfgfile = $ENV{HARNESS_ACTIVE} ? "t/benchmarkanything.cfg" : $ENV{BENCHMARKANYTHING_CONFIGFILE} || File::HomeDir->my_home . "/.benchmarkanything/default.cfg"; | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$ENV{"BENCHMARKANYTHING_CONFIGFILE"} or "File::HomeDir"->my_home . '/.benchmarkanything/default.cfg'
MC/DC0%0/1
$ENV{"BENCHMARKANYTHING_CONFIGFILE"} or "File::HomeDir"->my_home . '/.benchmarkanything/default.cfg'
$ENV{"BENCHMARKANYTHING_CONFIGFILE"}
Truth table50%1/2
A
A= $ENV{"BENCHMARKANYTHING_CONFIGFILE"}
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | # read file | ||||||||||||||||||||
| 31 | 3 | eval { | |||||||||||||||||||
| 32 | 3 | ▶ | $self->{cfgfile} = $self->{cfgfile} || $default_cfgfile; | ||||||||||||||||||
|
Condition66%2/3
$self->{'cfgfile'} || $default_cfgfile
MC/DC0%0/2
$self->{'cfgfile'} || $default_cfgfile
$self->{'cfgfile'}
$default_cfgfile
Truth table66%2/3
A || B
A= $self->{'cfgfile'}B= $default_cfgfile
| |||||||||||||||||||||
| 33 | 3 | my $cfg_yaml; | |||||||||||||||||||
| 34 | 3 | ▶ | open (my $CFG, "<", $self->{cfgfile}) or die "Can't read: ".$self->{cfgfile}."\n"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | { | ||||||||||||||||||||
| 36 | 3 | local $/; | |||||||||||||||||||
| 37 | 3 | $cfg_yaml = <$CFG>; | |||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | 3 | my $config = YAML::Any::Load($cfg_yaml); | |||||||||||||||||||
| 40 | 3 | $self->{benchmarkanything} = $config->{benchmarkanything}; | |||||||||||||||||||
| 41 | }; | ||||||||||||||||||||
| 42 | 3 | ▶ | if ($@) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | { | ||||||||||||||||||||
| 44 | 0 | die "benchmarkanything: error loading configfile: $@\n"; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | # defaults | ||||||||||||||||||||
| 48 | 3 | ▶ | $self->{benchmarkanything}{backend} ||= 'local'; | ||||||||||||||||||
|
Condition50%1/2
$self->{"benchmarkanything"}{"backend"} ||= "local"
MC/DC0%0/1
$self->{"benchmarkanything"}{"backend"} ||= "local"
$self->{"benchmarkanything"}{"backend"}
Truth table50%1/2
A
A= $self->{"benchmarkanything"}{"backend"}
| |||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 3 | return $self; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 2 | 1; | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | __END__ | ||||||||||||||||||||