line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
7391
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
83
|
|
2
|
3
|
|
|
3
|
|
12
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
112
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Smartcat::App::Config; |
5
|
3
|
|
|
3
|
|
12
|
use base ( "Class::Accessor", "Class::Data::Inheritable" ); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
675
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
4608
|
use Config::Tiny; |
|
3
|
|
|
|
|
2736
|
|
|
3
|
|
|
|
|
78
|
|
8
|
3
|
|
|
3
|
|
16
|
use File::Basename; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
195
|
|
9
|
3
|
|
|
3
|
|
16
|
use File::Spec::Functions qw(catfile); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
105
|
|
10
|
3
|
|
|
3
|
|
13318
|
use File::HomeDir; |
|
3
|
|
|
|
|
15092
|
|
|
3
|
|
|
|
|
168
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
509
|
use Data::Dumper; |
|
3
|
|
|
|
|
6193
|
|
|
3
|
|
|
|
|
1342
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
__PACKAGE__->mk_classdata( 'attribute_map' => {} ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
8
|
|
|
8
|
1
|
12
|
my $class = shift @_; |
18
|
|
|
|
|
|
|
|
19
|
8
|
|
|
|
|
17
|
my $self = bless( {}, $class ); |
20
|
|
|
|
|
|
|
|
21
|
8
|
|
|
|
|
26
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub validate_log { |
25
|
8
|
|
|
8
|
0
|
18
|
my ( $self, $value ) = @_; |
26
|
|
|
|
|
|
|
|
27
|
8
|
100
|
100
|
|
|
282
|
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
|
|
|
|
|
58
|
return 1; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub get_config_file { |
35
|
2
|
|
|
2
|
|
26
|
my $config_dir = |
36
|
|
|
|
|
|
|
File::HomeDir->my_dist_config( "Smartcat-App", { create => 1 } ); |
37
|
2
|
|
|
|
|
551
|
return catfile( $config_dir, 'config' ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub load { |
41
|
8
|
|
|
8
|
0
|
3347
|
my $self = shift @_; |
42
|
8
|
50
|
|
|
|
42
|
$self = $self->new unless ref $self; |
43
|
|
|
|
|
|
|
|
44
|
8
|
|
|
|
|
26
|
my $config_file = $self->get_config_file; |
45
|
8
|
100
|
|
|
|
178
|
if ( -e $config_file ) { |
46
|
5
|
|
|
|
|
41
|
$self->{instance} = Config::Tiny->read( $config_file, "utf8" ); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else { |
49
|
3
|
|
|
|
|
25
|
$self->{instance} = Config::Tiny->new; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
8
|
|
|
|
|
1902
|
foreach my $attribute ( keys %{ $self->attribute_map } ) { |
|
8
|
|
|
|
|
33
|
|
53
|
29
|
|
|
|
|
321
|
my $args_key = $self->attribute_map->{$attribute}; |
54
|
29
|
|
|
|
|
179
|
my $validate_attribute = "validate_$attribute"; |
55
|
29
|
|
|
|
|
45
|
my $value = $self->{instance}->{_}->{$args_key}; |
56
|
29
|
50
|
66
|
|
|
158
|
$self->$attribute($value) |
57
|
|
|
|
|
|
|
if !defined $self->can($validate_attribute) |
58
|
|
|
|
|
|
|
|| $self->$validate_attribute($value); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
7
|
|
|
|
|
93
|
return $self; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub save { |
65
|
1
|
|
|
1
|
0
|
1940
|
my $self = shift @_; |
66
|
1
|
|
|
|
|
2
|
foreach my $attribute ( keys %{ $self->attribute_map } ) { |
|
1
|
|
|
|
|
2
|
|
67
|
4
|
|
|
|
|
37
|
my $args_key = $self->attribute_map->{$attribute}; |
68
|
4
|
|
|
|
|
24
|
$self->{instance}->{_}->{$args_key} = $self->$attribute; |
69
|
|
|
|
|
|
|
} |
70
|
1
|
|
|
|
|
10
|
$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; |