File Coverage

blib/lib/Bundler/MultiGem/Utl/InitConfig.pm
Criterion Covered Total %
statement 33 33 100.0
branch 2 2 100.0
condition n/a
subroutine 10 10 100.0
pod 3 3 100.0
total 48 48 100.0


line stmt bran cond sub pod time code
1             package Bundler::MultiGem::Utl::InitConfig;
2              
3 4     4   76544 use 5.006;
  4         26  
4 4     4   22 use strict;
  4         7  
  4         78  
5 4     4   29 use warnings;
  4         10  
  4         124  
6              
7 4     4   23 use Exporter qw(import);
  4         8  
  4         215  
8             our @EXPORT = qw(ruby_constantize merge_configuration);
9              
10 4     4   2601 use Storable qw(dclone dclone);
  4         13146  
  4         281  
11 4     4   2031 use Hash::Merge qw(merge);
  4         22658  
  4         285  
12 4     4   1093 use common::sense;
  4         33  
  4         22  
13              
14             =head1 NAME
15              
16             Bundler::MultiGem::Utl::InitConfig - The utility to install multiple versions of the same ruby gem
17              
18             =head1 VERSION
19              
20             Version 0.02
21              
22             =cut
23             our $VERSION = '0.02';
24              
25             =head1 SYNOPSIS
26              
27             This module contains a default configuration for the package to work and the utility functions to manipulate it.
28              
29             =cut
30              
31             =head1 DEFAULT_CONFIGURATION
32              
33             Default configuration used to build the yaml configuration file:
34              
35             our $DEFAULT_CONFIGURATION = {
36             'gem' => {
37             'source' => 'https://rubygems.org',
38             'name' => undef,
39             'main_module' => undef,
40             'versions' => [()]
41             },
42             'directories' => {
43             'root' => undef,
44             'pkg' => 'pkg',
45             'target' => 'versions'
46             },
47             'cache' => {
48             'pkg' => 1,
49             'target' => 0
50             }
51             };
52              
53             =cut
54              
55             our $DEFAULT_CONFIGURATION = {
56             'gem' => {
57             'source' => 'https://rubygems.org',
58             'name' => undef,
59             'main_module' => undef,
60             'versions' => [()]
61             },
62             'directories' => {
63             'root' => undef,
64             'pkg' => 'pkg',
65             'target' => 'versions'
66             },
67             'cache' => {
68             'pkg' => 1,
69             'target' => 0
70             }
71             };
72              
73             =head1 EXPORTS
74              
75             =head2 merge_configuration
76              
77             Wrapper for merging a custom configuration with C<$DEFAULT_CONFIGURATION>
78              
79             =cut
80             sub merge_configuration {
81 1     1 1 4264 my $custom_config = shift;
82 1         91 my $result = merge($custom_config, dclone($DEFAULT_CONFIGURATION));
83 1         439 default_main_module($result);
84             }
85              
86             =head2 default_main_module
87              
88             Assing a default C name to a gem if not set
89              
90             my $gem_config = $custom_config->{gem};
91             ruby_constantize($gem_config->{name});
92              
93             E.g. C -> C, C -> C, C -> C
94              
95             =cut
96              
97             sub default_main_module {
98 3     3 1 2351 my $custom_config = shift;
99 3         7 my $gem_config = $custom_config->{gem};
100 3 100       10 if ( !defined $gem_config->{main_module}) {
101 2         7 $gem_config->{main_module} = ruby_constantize($gem_config->{name});
102             }
103             $custom_config
104 3         18 }
105              
106             =head2 ruby_constantize
107              
108             Format string as a ruby constant
109              
110             ruby_constantize("foo"); # Foo
111             ruby_constantize("foo_bar"); # FooBar
112             ruby_constantize("foo-bar"); # Foo::Bar
113             ruby_constantize("foo-bar_baz"); # Foo::BarBaz
114              
115             =cut
116              
117             sub ruby_constantize {
118 9     9 1 583 my $name = shift;
119 9         18 for ($name) {
120 9         50 s/_(\w)/\U$1/g;
121 9         56 s/-(\w)/::\U$1/g;
122             }
123 9         61 ucfirst $name;
124             }
125              
126             =head1 AUTHOR
127              
128             Mauro Berlanda, C<< >>
129              
130             =head1 BUGS
131              
132             Please report any bugs or feature requests to L, or through
133             the web interface at L. I will be notified, and then you'll
134             automatically be notified of progress on your bug as I make changes.
135              
136             =head1 SUPPORT
137              
138             You can find documentation for this module with the perldoc command.
139              
140             perldoc Bundler::MultiGem::Directories
141              
142              
143             You can also look for information at:
144              
145             =over 2
146              
147             =item * RT: CPAN's request tracker (report bugs here)
148              
149             L
150              
151             =item * Github Repository
152              
153             L
154              
155             =back
156              
157              
158             =head1 ACKNOWLEDGEMENTS
159              
160              
161             =head1 LICENSE AND COPYRIGHT
162              
163             Copyright 2018 Mauro Berlanda.
164              
165             This program is free software; you can redistribute it and/or modify it
166             under the terms of the the Artistic License (2.0). You may obtain a
167             copy of the full license at:
168              
169             L
170              
171             Any use, modification, and distribution of the Standard or Modified
172             Versions is governed by this Artistic License. By using, modifying or
173             distributing the Package, you accept this license. Do not use, modify,
174             or distribute the Package, if you do not accept this license.
175              
176             If your Modified Version has been derived from a Modified Version made
177             by someone other than you, you are nevertheless required to ensure that
178             your Modified Version complies with the requirements of this license.
179              
180             This license does not grant you the right to use any trademark, service
181             mark, tradename, or logo of the Copyright Holder.
182              
183             This license includes the non-exclusive, worldwide, free-of-charge
184             patent license to make, have made, use, offer to sell, sell, import and
185             otherwise transfer the Package with respect to any patent claims
186             licensable by the Copyright Holder that are necessarily infringed by the
187             Package. If you institute patent litigation (including a cross-claim or
188             counterclaim) against any party alleging that the Package constitutes
189             direct or contributory patent infringement, then this Artistic License
190             to you shall terminate on the date that such litigation is filed.
191              
192             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
193             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
194             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
195             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
196             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
197             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
198             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
199             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
200              
201              
202             =cut
203              
204             1;