| 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
Condition100%3/3
defined $value and not -d dirname($value)
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)
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 8 | my $config_file = $self->get_config_file; | |||||||||||||||||||||||||||
| 45 | 8 | ▶ | if ( -e $config_file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
not defined $self->can($validate_attribute) or $self->$validate_attribute($value)
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)
| |||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||