line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
792
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
95
|
|
2
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
137
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Smartcat::App::Config; |
5
|
3
|
|
|
3
|
|
16
|
use base ( "Class::Accessor", "Class::Data::Inheritable" ); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
963
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
5455
|
use Config::Tiny; |
|
3
|
|
|
|
|
3368
|
|
|
3
|
|
|
|
|
96
|
|
8
|
3
|
|
|
3
|
|
21
|
use File::Basename; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
215
|
|
9
|
3
|
|
|
3
|
|
17
|
use File::Spec::Functions qw(catfile); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
136
|
|
10
|
3
|
|
|
3
|
|
1734
|
use File::HomeDir; |
|
3
|
|
|
|
|
17893
|
|
|
3
|
|
|
|
|
188
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
676
|
use Data::Dumper; |
|
3
|
|
|
|
|
7263
|
|
|
3
|
|
|
|
|
1521
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
__PACKAGE__->mk_classdata( 'attribute_map' => {} ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
8
|
|
|
8
|
1
|
19
|
my $class = shift @_; |
18
|
|
|
|
|
|
|
|
19
|
8
|
|
|
|
|
19
|
my $self = bless( {}, $class ); |
20
|
|
|
|
|
|
|
|
21
|
8
|
|
|
|
|
22
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub validate_log { |
25
|
8
|
|
|
8
|
0
|
23
|
my ( $self, $value ) = @_; |
26
|
|
|
|
|
|
|
|
27
|
8
|
100
|
100
|
|
|
390
|
die |
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
|
|
|
|
|
63
|
return 1; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub get_config_file { |
35
|
2
|
|
|
2
|
|
17
|
my $config_dir = |
36
|
|
|
|
|
|
|
File::HomeDir->my_dist_config( "Smartcat-App", { create => 1 } ); |
37
|
2
|
|
|
|
|
731
|
return catfile( $config_dir, 'config' ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub load { |
41
|
8
|
|
|
8
|
0
|
18635
|
my $self = shift @_; |
42
|
8
|
50
|
|
|
|
49
|
$self = $self->new unless ref $self; |
43
|
|
|
|
|
|
|
|
44
|
8
|
|
|
|
|
32
|
my $config_file = $self->get_config_file; |
45
|
8
|
100
|
|
|
|
208
|
if ( -e $config_file ) { |
46
|
5
|
|
|
|
|
46
|
$self->{instance} = Config::Tiny->read( $config_file, "utf8" ); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else { |
49
|
3
|
|
|
|
|
29
|
$self->{instance} = Config::Tiny->new; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
8
|
|
|
|
|
2712
|
foreach my $attribute ( keys %{ $self->attribute_map } ) { |
|
8
|
|
|
|
|
35
|
|
53
|
30
|
|
|
|
|
446
|
my $args_key = $self->attribute_map->{$attribute}; |
54
|
30
|
|
|
|
|
328
|
my $validate_attribute = "validate_$attribute"; |
55
|
30
|
|
|
|
|
57
|
my $value = $self->{instance}->{_}->{$args_key}; |
56
|
30
|
50
|
66
|
|
|
256
|
$self->$attribute($value) |
57
|
|
|
|
|
|
|
if !defined $self->can($validate_attribute) |
58
|
|
|
|
|
|
|
|| $self->$validate_attribute($value); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
7
|
|
|
|
|
125
|
return $self; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub save { |
65
|
1
|
|
|
1
|
0
|
2274
|
my $self = shift @_; |
66
|
1
|
|
|
|
|
2
|
foreach my $attribute ( keys %{ $self->attribute_map } ) { |
|
1
|
|
|
|
|
3
|
|
67
|
4
|
|
|
|
|
42
|
my $args_key = $self->attribute_map->{$attribute}; |
68
|
4
|
|
|
|
|
31
|
$self->{instance}->{_}->{$args_key} = $self->$attribute; |
69
|
|
|
|
|
|
|
} |
70
|
1
|
|
|
|
|
37
|
$self->{instance}->write( $self->get_config_file, "utf8" ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub cat { |
74
|
0
|
|
|
0
|
0
|
|
my $self = shift @_; |
75
|
0
|
|
|
|
|
|
my $config_file = $self->get_config_file; |
76
|
0
|
|
|
|
|
|
print `cat $config_file\n`; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__PACKAGE__->attribute_map( |
80
|
|
|
|
|
|
|
{ |
81
|
|
|
|
|
|
|
'username' => 'token_id', |
82
|
|
|
|
|
|
|
'password' => 'token', |
83
|
|
|
|
|
|
|
'log' => 'log', |
84
|
|
|
|
|
|
|
'base_url' => 'base_url' |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( keys %{ __PACKAGE__->attribute_map } ); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |