App/Config.pm

filter: Statementstmt 94.9% 56 / 59 Branchbran 75.0% 6 / 8 Conditioncond 83.3% 5 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 92.8% 13 / 14 Podpod 20.0% 1 / 5 totaltotal 86.4% 83 / 96 CC 9 SCAR 10.3
CC
9
Cov
92%
load
6.1
validate_log
3.0
save
2.0
CRAP 2.8
« App/Command/project.pm ↑ Summary App/Utils.pm »
1 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Smartcat::App::Config;
5 3 ▶use base ( "Class::Accessor", "Class::Data::Inheritable" );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Config::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use File::Spec::Functions qw(catfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use File::HomeDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 __PACKAGE__->mk_classdata( 'attribute_map' => {} );
15  
16 8 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
17 8 my $class = shift @_;
18  
19 8 my $self = bless( {}, $class );
20  
21 8 return $self;
22 }
23  
24 8 ▶sub validate_log {
Subroutine validate_log: called CC=3 SCAR=11.0
Pod undocumented
25 8 my ( $self, $value ) = @_;
26  
27 8 ▶ die
Branch: 1 branch
BranchTrueFalseTotal
if defined $value and not -d dirname($value) 1 7 8
Condition100%3/3
defined $value and not -d dirname($value)
!ll&&!rl&&r
341
MC/DC100%2/2
defined $value and not -d dirname($value)
defined $value not -d dirname($value)
Truth table100%3/3
A and not(B)
A= defined $valueB= not -d dirname($value)
ABresult
0X0
100
111
28 "ConfigError: 'log' parent directory, which is set to '$value', does not point to a valid directory"
29 if defined $value && !-d dirname($value);
30  
31 7 return 1;
32 }
33  
34 2 ▶sub get_config_file {
Subroutine get_config_file: called CC=1 SCAR=0.0
35 2 my $config_dir =
36 File::HomeDir->my_dist_config( "Smartcat-App", { create => 1 } );
37 2 return catfile( $config_dir, 'config' );
38 }
39  
40 8 ▶sub load {
Subroutine load: called CC=6 SCAR=18.1
Pod undocumented
41 8 my $self = shift @_;
42 8 ▶ $self = $self->new unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 8 0 8
43  
44 8 my $config_file = $self->get_config_file;
45 8 ▶ if ( -e $config_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $config_file) { } 5 3 8
46 5 $self->{instance} = Config::Tiny->read( $config_file, "utf8" );
47 }
48 else {
49 3 $self->{instance} = Config::Tiny->new;
50 }
51  
52 8 foreach my $attribute ( keys %{ $self->attribute_map } ) {
53 32 my $args_key = $self->attribute_map->{$attribute};
54 32 my $validate_attribute = "validate_$attribute";
55 32 my $value = $self->{instance}->{_}->{$args_key};
56 32 ▶ $self->$attribute($value)
Branch: 1 branch
BranchTrueFalseTotal
if not defined $self->can($validate_attribute) or $self->$validate_attribute($value) 31 0 31
Condition66%2/3
not defined $self->can($validate_attribute) or $self->$validate_attribute($value)
l!l&&r!l&&!r
2480
MC/DC0%0/2
not defined $self->can($validate_attribute) or $self->$validate_attribute($value)
not defined $self->can($validate_attribute) $self->$validate_attribute($value)
Truth table66%2/3
not(A) or B
A= not defined $self->can($validate_attribute)B= $self->$validate_attribute($value)
ABresult
1X1
011
000
57 if !defined $self->can($validate_attribute)
58 || $self->$validate_attribute($value);
59 }
60  
61 7 return $self;
62 }
63  
64 1 ▶sub save {
Subroutine save: called CC=2 SCAR=6.9
Pod undocumented
65 1 my $self = shift @_;
66 1 foreach my $attribute ( keys %{ $self->attribute_map } ) {
67 4 my $args_key = $self->attribute_map->{$attribute};
68 4 $self->{instance}->{_}->{$args_key} = $self->$attribute;
69 }
70 1 $self->{instance}->write( $self->get_config_file, "utf8" );
71 }
72  
73 0 ▶sub cat {
Subroutine cat: not called CC=1 SCAR=6.9
Pod undocumented
74 0 my $self = shift @_;
75 0 my $config_file = $self->get_config_file;
76 0 print `cat $config_file\n`;
77 }
78  
79 3 __PACKAGE__->attribute_map(
80 {
81 'username' => 'token_id',
82 'password' => 'token',
83 'log' => 'log',
84 'base_url' => 'base_url'
85 }
86 );
87  
88 3 __PACKAGE__->mk_accessors( keys %{ __PACKAGE__->attribute_map } );
89  
90 3 1;
« App/Command/project.pm ↑ Summary App/Utils.pm »