line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bundler::MultiGem::Model::Directories; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
79192
|
use 5.006; |
|
2
|
|
|
|
|
16
|
|
4
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
38
|
|
5
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
55
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
444
|
use File::Spec::Functions qw(catpath); |
|
2
|
|
|
|
|
808
|
|
|
2
|
|
|
|
|
119
|
|
8
|
2
|
|
|
2
|
|
918
|
use Bundler::MultiGem::Utl::Directories qw(mk_dir rm_dir); |
|
2
|
|
|
|
|
17
|
|
|
2
|
|
|
|
|
155
|
|
9
|
2
|
|
|
2
|
|
15
|
use constant REQUIRED_KEYS => qw(cache directories); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
919
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Bundler::MultiGem::Model::Directory - Manipulate directories and cache |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Version 0.02 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
This package contain an object to manipulate directories and cache |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SUBROUTINES |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 new |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Takes an optional hash reference parameter |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $empty = Bundler::MultiGem::Model::Directories->new(); # {} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $config = { |
35
|
|
|
|
|
|
|
foo => 'bar', |
36
|
|
|
|
|
|
|
cache => [], |
37
|
|
|
|
|
|
|
directories => [], |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
my $foo = Bundler::MultiGem::Model::Directories->new($config); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
sub new { |
43
|
2
|
|
|
2
|
1
|
363
|
my ($class, $self) = @_; |
44
|
2
|
100
|
|
|
|
8
|
if (!defined $self) { $self = {}; } |
|
1
|
|
|
|
|
2
|
|
45
|
2
|
|
|
|
|
5
|
bless $self, $class; |
46
|
2
|
|
|
|
|
5
|
return $self; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 validates |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
C current configuration to contain REQUIRED_KEYS: |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
use constant REQUIRED_KEYS => qw(cache directories); |
54
|
|
|
|
|
|
|
$dir->validates; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
sub validates { |
58
|
2
|
|
|
2
|
1
|
1282
|
my $self = shift; |
59
|
2
|
|
|
|
|
8
|
my %keys = map { $_ => 1 } keys(%$self); |
|
3
|
|
|
|
|
9
|
|
60
|
2
|
|
|
|
|
6
|
foreach my $k (REQUIRED_KEYS) { |
61
|
3
|
100
|
|
|
|
10
|
if (! defined($keys{$k}) ) { |
62
|
1
|
|
|
|
|
12
|
die "Missing key: $k for Bundler::MultiGem::Model::Directories"; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
1
|
|
|
|
|
5
|
return $self; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 cache |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
C getter: if no arguments, return an hash reference |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$dir->{cache} = { foo => 1 }; |
73
|
|
|
|
|
|
|
$dir->cache; # { foo => 1 } |
74
|
|
|
|
|
|
|
$dir->cache('foo'); # 'bar' |
75
|
|
|
|
|
|
|
$dir->cache('baz'); # undef |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
sub cache { |
79
|
0
|
|
|
0
|
1
|
|
my ($self, $key) = @_; |
80
|
0
|
0
|
|
|
|
|
if (!defined $key) { |
81
|
0
|
|
|
|
|
|
return $self->{cache}; |
82
|
|
|
|
|
|
|
} |
83
|
0
|
|
|
|
|
|
return $self->{cache}->{$key} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 dirs |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
C getter: if no arguments, return an hash reference |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
$dir->{directories} = { foo => 'bar/' }; |
91
|
|
|
|
|
|
|
$dir->dirs; # { foo => 'bar/' } |
92
|
|
|
|
|
|
|
$dir->dirs('foo'); # '/root/bar' |
93
|
|
|
|
|
|
|
$dir->dirs('baz'); # undef |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub dirs { |
98
|
0
|
|
|
0
|
1
|
|
my ($self, $key) = @_; |
99
|
0
|
0
|
|
|
|
|
if (!defined $key) { |
|
|
0
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
return $self->{directories}; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
elsif ($key eq 'root') { |
103
|
0
|
|
|
|
|
|
return $self->{directories}->{root}; |
104
|
|
|
|
|
|
|
} |
105
|
0
|
|
|
|
|
|
return catpath($self->dirs('root'), $self->{directories}->{$key}); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 apply_cache |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
C handle configuration cache on the folder: |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
$dir->cache('foo'); # 1 |
113
|
|
|
|
|
|
|
$dir->dirs('foo'); # creates foo dir if not existing |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
$dir->cache('bar'); # 0 |
116
|
|
|
|
|
|
|
$dir->dirs('bar'); # deletes bar dir if existing and recreate it |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
119
|
|
|
|
|
|
|
sub apply_cache { |
120
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
121
|
0
|
|
|
|
|
|
my $root = $self->dirs('root'); |
122
|
0
|
|
|
|
|
|
mk_dir($root); |
123
|
0
|
|
|
|
|
|
foreach my $k (keys(%{$self->cache})){ |
|
0
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
|
if (! $self->cache->{$k}) { |
125
|
0
|
|
|
|
|
|
rm_dir $self->dirs($k); |
126
|
|
|
|
|
|
|
} |
127
|
0
|
|
|
|
|
|
mk_dir $self->dirs($k); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 AUTHOR |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Mauro Berlanda, C<< >> |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 BUGS |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Please report any bugs or feature requests to L, or through |
138
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
139
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 SUPPORT |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
perldoc Bundler::MultiGem::Directories |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
You can also look for information at: |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=over 2 |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
L |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item * Github Repository |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
L |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=back |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Copyright 2018 Mauro Berlanda. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
171
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
172
|
|
|
|
|
|
|
copy of the full license at: |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
L |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified |
177
|
|
|
|
|
|
|
Versions is governed by this Artistic License. By using, modifying or |
178
|
|
|
|
|
|
|
distributing the Package, you accept this license. Do not use, modify, |
179
|
|
|
|
|
|
|
or distribute the Package, if you do not accept this license. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made |
182
|
|
|
|
|
|
|
by someone other than you, you are nevertheless required to ensure that |
183
|
|
|
|
|
|
|
your Modified Version complies with the requirements of this license. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service |
186
|
|
|
|
|
|
|
mark, tradename, or logo of the Copyright Holder. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge |
189
|
|
|
|
|
|
|
patent license to make, have made, use, offer to sell, sell, import and |
190
|
|
|
|
|
|
|
otherwise transfer the Package with respect to any patent claims |
191
|
|
|
|
|
|
|
licensable by the Copyright Holder that are necessarily infringed by the |
192
|
|
|
|
|
|
|
Package. If you institute patent litigation (including a cross-claim or |
193
|
|
|
|
|
|
|
counterclaim) against any party alleging that the Package constitutes |
194
|
|
|
|
|
|
|
direct or contributory patent infringement, then this Artistic License |
195
|
|
|
|
|
|
|
to you shall terminate on the date that such litigation is filed. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER |
198
|
|
|
|
|
|
|
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. |
199
|
|
|
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
200
|
|
|
|
|
|
|
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY |
201
|
|
|
|
|
|
|
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR |
202
|
|
|
|
|
|
|
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR |
203
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, |
204
|
|
|
|
|
|
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=cut |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
1; |