line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package P5U::Command; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
BEGIN { |
4
|
1
|
|
|
1
|
|
814
|
$P5U::Command::AUTHORITY = 'cpan:TOBYINK'; |
5
|
1
|
|
|
|
|
17
|
$P5U::Command::VERSION = '0.100'; |
6
|
|
|
|
|
|
|
}; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
21
|
use 5.010; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
9
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
26
|
|
|
1
|
|
|
|
|
42
|
|
10
|
1
|
|
|
1
|
|
5
|
use App::Cmd::Setup-command; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
1023
|
use File::HomeDir qw<>; |
|
1
|
|
|
|
|
6649
|
|
|
1
|
|
|
|
|
29
|
|
13
|
1
|
|
|
1
|
|
1315
|
use File::Temp qw<>; |
|
1
|
|
|
|
|
38069
|
|
|
1
|
|
|
|
|
176
|
|
14
|
1
|
|
|
1
|
|
1920
|
use JSON qw<>; |
|
1
|
|
|
|
|
27452
|
|
|
1
|
|
|
|
|
27
|
|
15
|
1
|
|
|
1
|
|
2552
|
use Path::Tiny qw<>; |
|
1
|
|
|
|
|
34284
|
|
|
1
|
|
|
|
|
243
|
|
16
|
1
|
|
|
1
|
|
1094
|
use Object::AUTHORITY; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my %config; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub get_tempdir |
21
|
|
|
|
|
|
|
{ |
22
|
|
|
|
|
|
|
Path::Tiny::->tempdir; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _get_distdatadir |
26
|
|
|
|
|
|
|
{ |
27
|
|
|
|
|
|
|
File::HomeDir::->my_dist_data('P5U') // |
28
|
|
|
|
|
|
|
Path::Tiny::->new(File::HomeDir::->my_home => qw(perl5 utils data))->stringify |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _get_distconfigdir |
32
|
|
|
|
|
|
|
{ |
33
|
|
|
|
|
|
|
File::HomeDir::->my_dist_data('P5U') // |
34
|
|
|
|
|
|
|
Path::Tiny::->new(File::HomeDir::->my_home => qw(perl5 utils etc))->stringify |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub get_cachedir |
38
|
|
|
|
|
|
|
{ |
39
|
|
|
|
|
|
|
my $self = shift; |
40
|
|
|
|
|
|
|
my $d = Path::Tiny::->new( |
41
|
|
|
|
|
|
|
$self->_get_distdatadir, |
42
|
|
|
|
|
|
|
(($self->command_names)[0]), |
43
|
|
|
|
|
|
|
'cache', |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
$d->mkpath; |
46
|
|
|
|
|
|
|
return $d; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub get_datadir |
50
|
|
|
|
|
|
|
{ |
51
|
|
|
|
|
|
|
my $self = shift; |
52
|
|
|
|
|
|
|
my $d = Path::Tiny::->new( |
53
|
|
|
|
|
|
|
$self->_get_distdatadir, |
54
|
|
|
|
|
|
|
(($self->command_names)[0]), |
55
|
|
|
|
|
|
|
'store', |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
$d->mkpath; |
58
|
|
|
|
|
|
|
return $d; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub get_configfile |
62
|
|
|
|
|
|
|
{ |
63
|
|
|
|
|
|
|
my $self = shift; |
64
|
|
|
|
|
|
|
my $f = Path::Tiny::->new( |
65
|
|
|
|
|
|
|
$self->_get_distconfigdir, |
66
|
|
|
|
|
|
|
(($self->command_names)[0]), |
67
|
|
|
|
|
|
|
'config.json', |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub get_config |
72
|
|
|
|
|
|
|
{ |
73
|
|
|
|
|
|
|
my $proto = shift; |
74
|
|
|
|
|
|
|
my $class = ref($proto) || $proto; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
unless ($config{$class}) |
77
|
|
|
|
|
|
|
{ |
78
|
|
|
|
|
|
|
$config{$class} = |
79
|
|
|
|
|
|
|
eval { JSON::->new->decode(scalar $proto->get_configfile->slurp) } |
80
|
|
|
|
|
|
|
|| +{}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$config{$class}; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub save_config |
87
|
|
|
|
|
|
|
{ |
88
|
|
|
|
|
|
|
my $proto = shift; |
89
|
|
|
|
|
|
|
my $class = ref($proto) || $proto; |
90
|
|
|
|
|
|
|
my $config = $config{$class} || +{}; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
my $fh = $proto->get_configfile->openw; |
93
|
|
|
|
|
|
|
print $fh $config; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|