MultiGem/Utl/InitConfig.pm

filter: Statementstmt 100% 37 / 37 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 3 / 3 totaltotal 100% 52 / 52 CC 3 SCAR 2.9
CC
3
Cov
100%
default_main_module
2.0
ruby_constantize
2.0
BEGIN
1.0
CRAP 1.3
« MultiGem/Model/Directories.pm ↑ Summary MultiGem.pm »
1 package Bundler::MultiGem::Utl::InitConfig;
2  
3 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 our @EXPORT = qw(ruby_constantize merge_configuration);
9  
10 4 ▶use Storable qw(dclone dclone);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Hash::Merge qw(merge);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 4 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 4 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 1 ▶sub merge_configuration {
Subroutine merge_configuration: called CC=1 SCAR=0.0
Pod documented
81 1 my $custom_config = shift;
82 1 my $result = merge($custom_config, dclone($DEFAULT_CONFIGURATION));
83 1 default_main_module($result);
84 }
85  
86 =head2 default_main_module
87  
88 Assing a default C<main_module> 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<foo> -> C<Foo>, C<foo_bar> -> C<FooBar>, C<foo-bar> -> C<Foo::Bar>
94  
95 =cut
96  
97 3 ▶sub default_main_module {
Subroutine default_main_module: called CC=2 SCAR=6.9
Pod documented
98 3 my $custom_config = shift;
99 3 my $gem_config = $custom_config->{gem};
100 3 ▶ if ( !defined $gem_config->{main_module}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $gem_config->{"main_module"}) 2 1 3
101 2 $gem_config->{main_module} = ruby_constantize($gem_config->{name});
102 }
103 $custom_config
104 3 }
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 9 ▶sub ruby_constantize {
Subroutine ruby_constantize: called CC=2 SCAR=6.9
Pod documented
118 9 my $name = shift;
119 9 for ($name) {
120 9 s/_(\w)/\U$1/g;
121 9 s/-(\w)/::\U$1/g;
122 }
123 9 ucfirst $name;
124 }
125  
126 =head1 AUTHOR
127  
128 Mauro Berlanda, C<< <kupta at cpan.org> >>
129  
130 =head1 BUGS
131  
132 Please report any bugs or feature requests to L<https://github.com/mberlanda/Bundler-MultiGem/issues>, or through
133 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=.>. 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<https://rt.cpan.org/Public/Dist/Display.html?Name=Bundler-MultiGem>
150  
151 =item * Github Repository
152  
153 L<https://github.com/mberlanda/Bundler-MultiGem>
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<http://www.perlfoundation.org/artistic_license_2_0>
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 4 1;
« MultiGem/Model/Directories.pm ↑ Summary MultiGem.pm »