line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::VTide::Config; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Created on: 2016-01-28 10:29:47 |
4
|
|
|
|
|
|
|
# Create by: Ivan Wills |
5
|
|
|
|
|
|
|
# $Id$ |
6
|
|
|
|
|
|
|
# $Revision$, $HeadURL$, $Date$ |
7
|
|
|
|
|
|
|
# $Revision$, $Source$, $Date$ |
8
|
|
|
|
|
|
|
|
9
|
7
|
|
|
7
|
|
1268
|
use Moo; |
|
7
|
|
|
|
|
11588
|
|
|
7
|
|
|
|
|
69
|
|
10
|
7
|
|
|
7
|
|
17367
|
use warnings; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
202
|
|
11
|
7
|
|
|
7
|
|
482
|
use version; |
|
7
|
|
|
|
|
1908
|
|
|
7
|
|
|
|
|
96
|
|
12
|
7
|
|
|
7
|
|
501
|
use Carp; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
506
|
|
13
|
7
|
|
|
7
|
|
549
|
use English qw/ -no_match_vars /; |
|
7
|
|
|
|
|
1628
|
|
|
7
|
|
|
|
|
56
|
|
14
|
7
|
|
|
7
|
|
3874
|
use Path::Tiny; |
|
7
|
|
|
|
|
12759
|
|
|
7
|
|
|
|
|
395
|
|
15
|
7
|
|
|
7
|
|
3715
|
use YAML::Syck qw/ LoadFile /; |
|
7
|
|
|
|
|
14908
|
|
|
7
|
|
|
|
|
543
|
|
16
|
7
|
|
|
7
|
|
3398
|
use Hash::Merge::Simple qw/ merge /; |
|
7
|
|
|
|
|
3703
|
|
|
7
|
|
|
|
|
6322
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = version->new('1.0.4'); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has global_base => ( |
21
|
|
|
|
|
|
|
is => 'rw', |
22
|
|
|
|
|
|
|
default => sub { |
23
|
|
|
|
|
|
|
mkdir path $ENV{HOME}, '.vtide' if !-d path $ENV{HOME}, '.vtide'; |
24
|
|
|
|
|
|
|
return path $ENV{HOME}, '.vtide'; |
25
|
|
|
|
|
|
|
}, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
has global_config => ( |
28
|
|
|
|
|
|
|
is => 'rw', |
29
|
|
|
|
|
|
|
lazy => 1, |
30
|
|
|
|
|
|
|
default => sub { |
31
|
|
|
|
|
|
|
return path $_[0]->global_base, 'defaults.yml'; |
32
|
|
|
|
|
|
|
}, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has history_file => ( |
36
|
|
|
|
|
|
|
is => 'rw', |
37
|
|
|
|
|
|
|
default => sub { |
38
|
|
|
|
|
|
|
if ( $ENV{VTIDE_DIR} && -d $ENV{VTIDE_DIR} ) { |
39
|
|
|
|
|
|
|
mkdir path $ENV{VTIDE_DIR}, '.vtide' |
40
|
|
|
|
|
|
|
if !-d path $ENV{VTIDE_DIR}, '.vtide'; |
41
|
|
|
|
|
|
|
return path $ENV{VTIDE_DIR}, '.vtide/history.log'; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
mkdir path $ENV{HOME}, '.vtide' if !-d path $ENV{HOME}, '.vtide'; |
45
|
|
|
|
|
|
|
return path $ENV{HOME}, '.vtide/history.log'; |
46
|
|
|
|
|
|
|
}, |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has local_base => ( |
50
|
|
|
|
|
|
|
is => 'rw', |
51
|
|
|
|
|
|
|
lazy => 1, |
52
|
|
|
|
|
|
|
default => sub { return path $ENV{VTIDE_DIR}, '.vtide' || '.vtide' }, |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
has local_config => ( |
55
|
|
|
|
|
|
|
is => 'rw', |
56
|
|
|
|
|
|
|
lazy => 1, |
57
|
|
|
|
|
|
|
default => sub { return path $ENV{VTIDE_CONFIG} || '.vtide.yml' }, |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
has [qw/ global_time local_time /] => ( |
61
|
|
|
|
|
|
|
is => 'rw', |
62
|
|
|
|
|
|
|
lazy => 1, |
63
|
|
|
|
|
|
|
default => 0, |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
has data => ( is => 'rw', ); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub get { |
69
|
6
|
|
|
6
|
1
|
1856
|
my ($self) = @_; |
70
|
|
|
|
|
|
|
|
71
|
6
|
100
|
|
|
|
14
|
if ( $self->changed ) { |
72
|
5
|
|
|
|
|
80
|
my $global_time = ( stat $self->global_config )[9]; |
73
|
5
|
|
|
|
|
177
|
my $local_time = ( stat $self->local_config )[9]; |
74
|
|
|
|
|
|
|
|
75
|
5
|
|
|
|
|
184
|
$self->global_time($global_time); |
76
|
5
|
|
|
|
|
99
|
$self->local_time($local_time); |
77
|
|
|
|
|
|
|
|
78
|
5
|
|
100
|
|
|
34
|
my $global = eval { LoadFile( $self->global_config ); } || {}; |
79
|
5
|
|
100
|
|
|
705
|
my $local = eval { LoadFile( $self->local_config ); } || {}; |
80
|
|
|
|
|
|
|
|
81
|
5
|
50
|
|
|
|
580
|
if ( $local->{parent} ) { |
82
|
0
|
|
0
|
|
|
0
|
my $parent = eval { LoadFile( $local->{parent} ); } || {}; |
83
|
0
|
|
|
|
|
0
|
$local = merge $parent, $local; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
5
|
|
|
|
|
16
|
$self->data( merge $global, $local ); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
6
|
|
|
|
|
184
|
return $self->data; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub changed { |
93
|
9
|
|
|
9
|
1
|
86
|
my ($self) = @_; |
94
|
9
|
|
|
|
|
193
|
my $global_orig = $self->global_time; |
95
|
9
|
|
|
|
|
186
|
my $local_orig = $self->local_time; |
96
|
|
|
|
|
|
|
|
97
|
9
|
|
|
|
|
174
|
my $global_time = ( stat $self->global_config )[9]; |
98
|
9
|
|
|
|
|
396
|
my $local_time = ( stat $self->local_config )[9]; |
99
|
|
|
|
|
|
|
|
100
|
9
|
|
|
|
|
366
|
$self->global_time($global_time); |
101
|
9
|
|
|
|
|
187
|
$self->local_time($local_time); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
return |
104
|
9
|
|
33
|
|
|
112
|
!$self->data |
105
|
|
|
|
|
|
|
|| ( $global_time && $global_orig < $global_time ) |
106
|
|
|
|
|
|
|
|| ( $local_time && $local_orig < $local_time ); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub history { |
110
|
0
|
|
|
0
|
1
|
|
my ( $self, @command ) = @_; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
return |
113
|
0
|
0
|
0
|
|
|
|
if $command[0] eq 'run' || grep { $_ eq '--auto-complete' } @command; |
|
0
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
my $fh = $self->history_file->opena; |
116
|
0
|
|
|
|
|
|
print {$fh} '[' |
117
|
|
|
|
|
|
|
. localtime . '] ' |
118
|
0
|
0
|
|
|
|
|
. ( join ' ', map { /[^\w.\/-]/ ? "'$_'" : $_ } @command ), "\n"; |
|
0
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
return; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 NAME |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
App::VTide::Config - Manage configuration for VTide |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 VERSION |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This documentation refers to App::VTide::Config version 1.0.4 |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 SYNOPSIS |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
use App::VTide::Config; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
my $config = App::VTide::Config->new( |
139
|
|
|
|
|
|
|
global_config => "$ENV{HOME}/.vtide/defaults.yml", |
140
|
|
|
|
|
|
|
local_config => './.vtide.yml', |
141
|
|
|
|
|
|
|
); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
$config->get(); |
144
|
|
|
|
|
|
|
# returns the merged global and local configurations (will always be up |
145
|
|
|
|
|
|
|
# to date with files on disk i.e. files are checked for changes on each |
146
|
|
|
|
|
|
|
# call) |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 DESCRIPTION |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
This module gets the global L<App::VTide> configuration and the local |
151
|
|
|
|
|
|
|
project configuration data and returns the merged configuration. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 C<get ()> |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Get the merged local and global configuration files. The files are scanned |
158
|
|
|
|
|
|
|
for changes each call so the current values are always returned. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 C<changed ()> |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Returns true if either the C<global_config> or C<local_config> files have |
163
|
|
|
|
|
|
|
changed since the last read. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 C<history (@command)> |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Store C<@command> in history |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 global_config |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
The name of the global configuration file (Defaults to ~/.vtide/defaults.yml) |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head2 local_config |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
The name of the current project's configuration file (Defaults to ./.vtide.yml) |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 global_time |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Last modified time for the C<global_config> file (Defaults to 0) |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head2 history_file |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
File to store command history |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head2 local_time |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Last modified time for the C<local_config> file (Defaults to 0) |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head2 data |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Cached combined global/local data |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
There are no known bugs in this module. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Please report problems to Ivan Wills (ivan.wills@gmail.com). |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Patches are welcome. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 AUTHOR |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Ivan Wills - (ivan.wills@gmail.com) |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Copyright (c) 2016 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). |
218
|
|
|
|
|
|
|
All rights reserved. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under |
221
|
|
|
|
|
|
|
the same terms as Perl itself. See L<perlartistic>. This program is |
222
|
|
|
|
|
|
|
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
223
|
|
|
|
|
|
|
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
224
|
|
|
|
|
|
|
PARTICULAR PURPOSE. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=cut |