| 1 | package Bundler::MultiGem::Model::Directories; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 2 | ▶ | use 5.006; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 2 | ▶ | use File::Spec::Functions qw(catpath); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 2 | ▶ | use Bundler::MultiGem::Utl::Directories qw(mk_dir rm_dir); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 2 | ▶ | use constant REQUIRED_KEYS => qw(cache directories); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 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 | 2 | 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 | 2 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 43 | 2 | my ($class, $self) = @_; | |||||||||||||
| 44 | 2 | ▶ | if (!defined $self) { $self = {}; } | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 45 | 2 | bless $self, $class; | |||||||||||||
| 46 | 2 | return $self; | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | |||||||||||||||
| 49 | =head2 validates | ||||||||||||||
| 50 | |||||||||||||||
| 51 | C<validates> current configuration to contain REQUIRED_KEYS: | ||||||||||||||
| 52 | |||||||||||||||
| 53 | use constant REQUIRED_KEYS => qw(cache directories); | ||||||||||||||
| 54 | $dir->validates; | ||||||||||||||
| 55 | |||||||||||||||
| 56 | =cut | ||||||||||||||
| 57 | 2 | ▶ | sub validates { | ||||||||||||
|
Subroutine
validates: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||
| 58 | 2 | my $self = shift; | |||||||||||||
| 59 | 2 | my %keys = map { $_ => 1 } keys(%$self); | |||||||||||||
| 60 | 2 | foreach my $k (REQUIRED_KEYS) { | |||||||||||||
| 61 | 3 | ▶ | if (! defined($keys{$k}) ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 62 | 1 | die "Missing key: $k for Bundler::MultiGem::Model::Directories"; | |||||||||||||
| 63 | } | ||||||||||||||
| 64 | } | ||||||||||||||
| 65 | 1 | return $self; | |||||||||||||
| 66 | } | ||||||||||||||
| 67 | |||||||||||||||
| 68 | =head2 cache | ||||||||||||||
| 69 | |||||||||||||||
| 70 | C<cache> 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 | 0 | ▶ | sub cache { | ||||||||||||
|
Subroutine
cache: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 79 | 0 | my ($self, $key) = @_; | |||||||||||||
| 80 | 0 | ▶ | if (!defined $key) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 81 | 0 | return $self->{cache}; | |||||||||||||
| 82 | } | ||||||||||||||
| 83 | 0 | return $self->{cache}->{$key} | |||||||||||||
| 84 | } | ||||||||||||||
| 85 | |||||||||||||||
| 86 | =head2 dirs | ||||||||||||||
| 87 | |||||||||||||||
| 88 | C<dirs> 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 | 0 | ▶ | sub dirs { | ||||||||||||
|
Subroutine
dirs: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||
| 98 | 0 | my ($self, $key) = @_; | |||||||||||||
| 99 | 0 | ▶ | if (!defined $key) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 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<apply_cache> 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 | 0 | ▶ | sub apply_cache { | ||||||||||||
|
Subroutine
apply_cache: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||
| 120 | 0 | my $self = shift; | |||||||||||||
| 121 | 0 | my $root = $self->dirs('root'); | |||||||||||||
| 122 | 0 | mk_dir($root); | |||||||||||||
| 123 | 0 | foreach my $k (keys(%{$self->cache})){ | |||||||||||||
| 124 | 0 | ▶ | if (! $self->cache->{$k}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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<< <kupta at cpan.org> >> | ||||||||||||||
| 134 | |||||||||||||||
| 135 | =head1 BUGS | ||||||||||||||
| 136 | |||||||||||||||
| 137 | Please report any bugs or feature requests to L<https://github.com/mberlanda/Bundler-MultiGem/issues>, or through | ||||||||||||||
| 138 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=.>. 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<https://rt.cpan.org/Public/Dist/Display.html?Name=Bundler-MultiGem> | ||||||||||||||
| 155 | |||||||||||||||
| 156 | =item * Github Repository | ||||||||||||||
| 157 | |||||||||||||||
| 158 | L<https://github.com/mberlanda/Bundler-MultiGem> | ||||||||||||||
| 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<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||||
| 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 | 2 | 1; | |||||||||||||