| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Config::Pit; |
|
2
|
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
107800
|
use strict; |
|
|
3
|
|
|
|
|
9
|
|
|
|
3
|
|
|
|
|
105
|
|
|
4
|
3
|
|
|
3
|
|
38
|
use 5.8.1; |
|
|
3
|
|
|
|
|
10
|
|
|
|
3
|
|
|
|
|
128
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
15
|
use base qw/Exporter/; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
537
|
|
|
7
|
|
|
|
|
|
|
our @EXPORT = qw/pit_get pit_set pit_switch/; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
*pit_get = \&get; |
|
10
|
|
|
|
|
|
|
*pit_set = \&set; |
|
11
|
|
|
|
|
|
|
*pit_switch = \&switch; |
|
12
|
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
1888
|
use YAML::Syck; |
|
|
3
|
|
|
|
|
4470
|
|
|
|
3
|
|
|
|
|
182
|
|
|
14
|
3
|
|
|
3
|
|
955
|
use Path::Class; |
|
|
3
|
|
|
|
|
65169
|
|
|
|
3
|
|
|
|
|
198
|
|
|
15
|
3
|
|
|
3
|
|
4341
|
use File::HomeDir; |
|
|
3
|
|
|
|
|
22313
|
|
|
|
3
|
|
|
|
|
303
|
|
|
16
|
3
|
|
|
3
|
|
32
|
use File::Spec; |
|
|
3
|
|
|
|
|
41
|
|
|
|
3
|
|
|
|
|
70
|
|
|
17
|
3
|
|
|
3
|
|
15
|
use File::Temp; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
314
|
|
|
18
|
3
|
|
|
3
|
|
2811
|
use List::MoreUtils qw(all); |
|
|
3
|
|
|
|
|
3498
|
|
|
|
3
|
|
|
|
|
2761
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
|
21
|
|
|
|
|
|
|
our $directory = dir(File::HomeDir->my_home, ".pit"); |
|
22
|
|
|
|
|
|
|
our $config_file = $directory->file("pit.yaml"); |
|
23
|
|
|
|
|
|
|
our $profile_file = undef; |
|
24
|
|
|
|
|
|
|
our $verbose = 1; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub get { |
|
27
|
7
|
|
|
7
|
1
|
1095
|
my ($name, %opts) = @_; |
|
28
|
7
|
|
|
|
|
20
|
my $profile = _load(); |
|
29
|
7
|
|
|
|
|
952
|
local $YAML::Syck::ImplicitTyping = 1; |
|
30
|
7
|
|
|
|
|
14
|
local $YAML::Syck::SingleQuote = 1; |
|
31
|
|
|
|
|
|
|
|
|
32
|
7
|
50
|
|
|
|
23
|
if ($opts{require}) { |
|
33
|
0
|
0
|
|
0
|
|
0
|
unless (all { defined $profile->{$name}->{$_} } keys %{$opts{require}}) { |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
34
|
|
|
|
|
|
|
# merge |
|
35
|
0
|
|
|
|
|
0
|
my %t = (%{$opts{require}}, %{$profile->{$name}}); |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
36
|
0
|
|
|
|
|
0
|
$profile->{$name} = set($name, config => \%t); |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
} |
|
39
|
7
|
|
100
|
|
|
56
|
return $profile->{$name} || {}; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub set { |
|
43
|
5
|
|
|
5
|
1
|
2132
|
my ($name, %opts) = @_; |
|
44
|
5
|
|
|
|
|
8
|
my $result = {}; |
|
45
|
5
|
|
|
|
|
8
|
local $YAML::Syck::ImplicitTyping = 1; |
|
46
|
5
|
|
|
|
|
6
|
local $YAML::Syck::SingleQuote = 1; |
|
47
|
|
|
|
|
|
|
|
|
48
|
5
|
100
|
|
|
|
12
|
if ($opts{data}) { |
|
49
|
3
|
|
|
|
|
6
|
$result = $opts{data}; |
|
50
|
|
|
|
|
|
|
} else { |
|
51
|
2
|
100
|
|
|
|
10
|
return {} unless $ENV{EDITOR}; |
|
52
|
1
|
|
33
|
|
|
8
|
my $setting = $opts{config} || get($name); |
|
53
|
|
|
|
|
|
|
# system |
|
54
|
1
|
|
|
|
|
6
|
my $f = File::Temp->new(SUFFIX => ".yaml"); |
|
55
|
1
|
|
|
|
|
331
|
print $f YAML::Syck::Dump($setting); |
|
56
|
1
|
|
|
|
|
60
|
close $f; |
|
57
|
1
|
|
|
|
|
5
|
my $t = file($f->filename)->stat->mtime; |
|
58
|
1
|
|
|
|
|
339
|
system $ENV{EDITOR}, $f->filename; |
|
59
|
1
|
50
|
|
|
|
12657
|
if ($t == file($f->filename)->stat->mtime) { |
|
60
|
1
|
50
|
|
|
|
1164
|
print STDERR "No changes." if $verbose; |
|
61
|
1
|
|
|
|
|
17
|
$result = get($name); |
|
62
|
|
|
|
|
|
|
} else { |
|
63
|
0
|
|
|
|
|
0
|
$result = set($name, data => YAML::Syck::LoadFile($f->filename)); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
} |
|
66
|
4
|
|
|
|
|
297
|
my $profile = _load(); |
|
67
|
4
|
|
|
|
|
590
|
$profile->{$name} = $result; |
|
68
|
4
|
|
|
|
|
15
|
YAML::Syck::DumpFile($profile_file, $profile); |
|
69
|
4
|
|
|
|
|
577
|
return $result; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub switch { |
|
73
|
13
|
|
|
13
|
1
|
26
|
my ($name, %opts) = @_; |
|
74
|
13
|
|
|
|
|
20
|
local $YAML::Syck::ImplicitTyping = 1; |
|
75
|
13
|
|
|
|
|
16
|
local $YAML::Syck::SingleQuote = 1; |
|
76
|
|
|
|
|
|
|
|
|
77
|
13
|
|
100
|
|
|
24
|
$name ||= "default"; |
|
78
|
|
|
|
|
|
|
|
|
79
|
13
|
|
|
|
|
104
|
$profile_file = File::Spec->catfile($directory, "$name.yaml"); |
|
80
|
|
|
|
|
|
|
|
|
81
|
13
|
|
|
|
|
252
|
my $config = _config(); |
|
82
|
13
|
|
|
|
|
26
|
my $ret = $config->{profile}; |
|
83
|
13
|
|
|
|
|
18
|
$config->{profile} = $name; |
|
84
|
13
|
|
|
|
|
34
|
YAML::Syck::DumpFile($config_file, $config); |
|
85
|
13
|
50
|
33
|
|
|
2922
|
print STDERR "Config::Pit: Profile switch to $name from $ret.\n" if $verbose && ($name ne $ret); |
|
86
|
13
|
|
|
|
|
43
|
return $ret; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub pipe { |
|
90
|
0
|
|
|
0
|
0
|
0
|
local $YAML::Syck::ImplicitTyping = 1; |
|
91
|
0
|
|
|
|
|
0
|
local $YAML::Syck::SingleQuote = 1; |
|
92
|
|
|
|
|
|
|
|
|
93
|
0
|
0
|
|
|
|
0
|
-t STDOUT ? print STDERR 'do not output to tty.' : print Dump(get(shift)), "\n"; ## no critic |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _load { |
|
97
|
11
|
|
|
11
|
|
22
|
my $config = _config(); |
|
98
|
11
|
|
|
|
|
20
|
local $YAML::Syck::ImplicitTyping = 1; |
|
99
|
11
|
|
|
|
|
13
|
local $YAML::Syck::SingleQuote = 1; |
|
100
|
|
|
|
|
|
|
|
|
101
|
11
|
|
|
|
|
32
|
switch($config->{profile}); |
|
102
|
|
|
|
|
|
|
|
|
103
|
11
|
100
|
|
|
|
251
|
unless (-e $profile_file) { |
|
104
|
2
|
|
|
|
|
10
|
YAML::Syck::DumpFile($profile_file, {}); |
|
105
|
|
|
|
|
|
|
} |
|
106
|
11
|
|
|
|
|
289
|
return YAML::Syck::LoadFile($profile_file); |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub _config { |
|
110
|
24
|
|
|
24
|
|
37
|
local $YAML::Syck::ImplicitTyping = 1; |
|
111
|
24
|
|
|
|
|
24
|
local $YAML::Syck::SingleQuote = 1; |
|
112
|
|
|
|
|
|
|
|
|
113
|
24
|
50
|
|
|
|
74
|
(-e $directory) || $directory->mkpath(0, 0700); |
|
114
|
|
|
|
|
|
|
|
|
115
|
24
|
|
100
|
|
|
817
|
my $config = eval { YAML::Syck::LoadFile($config_file) } || ({ |
|
116
|
|
|
|
|
|
|
profile => "default" |
|
117
|
|
|
|
|
|
|
}); |
|
118
|
24
|
|
|
|
|
5778
|
return $config; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
|
123
|
|
|
|
|
|
|
__END__ |