| 1 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # Copyright © 2012-2018 -- LIRMM/UM # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # (Laboratoire d'Informatique, de Robotique et de # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Microélectronique de Montpellier / # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # Université de Montpellier) # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # IRB/INSERM # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # (Institut de Recherche en Biothérapie / # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # Institut National de la Santé et de la # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # Recherche Médicale) # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # Auteurs/Authors: Alban MANCHERON <alban.mancheron@lirmm.fr> # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # Nicolas PHILIPPE <nicolas.philippe@inserm.fr> # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # ------------------------------------------------------------------------- # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # Ce fichier fait partie du Pipeline de traitement de données NGS de la # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # plateforme ATGC labélisée par le GiS IBiSA. # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # Ce logiciel est régi par la licence CeCILL soumise au droit français et # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # respectant les principes de diffusion des logiciels libres. Vous pouvez # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # utiliser, modifier et/ou redistribuer ce programme sous les conditions de # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA sur # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # le site "http://www.cecill.info". # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # En contrepartie de l'accessibilité au code source et des droits de copie, # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # de modification et de redistribution accordés par cette licence, il n'est # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons, # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # seule une responsabilité restreinte pèse sur l'auteur du programme, le # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # titulaire des droits patrimoniaux et les concédants successifs. # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # À cet égard l'attention de l'utilisateur est attirée sur les risques # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # associés au chargement, à l'utilisation, à la modification et/ou au # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # développement et à la reproduction du logiciel par l'utilisateur étant # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # donné sa spécificité de logiciel libre, qui peut le rendre complexe à # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # manipuler et qui le réserve donc à des développeurs et des professionnels # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # avertis possédant des connaissances informatiques approfondies. Les # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # utilisateurs sont donc invités à charger et tester l'adéquation du # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # logiciel à leurs besoins dans des conditions permettant d'assurer la # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # sécurité de leurs systêmes et ou de leurs données et, plus généralement, # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # à l'utiliser et l'exploiter dans les mêmes conditions de sécurité. # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # Le fait que vous puissiez accéder à cet en-tête signifie que vous avez # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # pris connaissance de la licence CeCILL, et que vous en avez accepté les # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # termes. # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # ------------------------------------------------------------------------- # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # This File is part of the NGS data processing Pipeline of the ATGC # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # accredited by the IBiSA GiS. # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # This software is governed by the CeCILL license under French law and # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # abiding by the rules of distribution of free software. You can use, # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # modify and/ or redistribute the software under the terms of the CeCILL # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # license as circulated by CEA, CNRS and INRIA at the following URL # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # "http://www.cecill.info". # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # As a counterpart to the access to the source code and rights to copy, # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # modify and redistribute granted by the license, users are provided only # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # with a limited warranty and the software's author, the holder of the # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # economic rights, and the successive licensors have only limited # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # liability. # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # In this respect, the user's attention is drawn to the risks associated # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # with loading, using, modifying and/or developing or reproducing the # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # software by the user in light of its specific status of free software, # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # that may mean that it is complicated to manipulate, and that also # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # therefore means that it is reserved for developers and experienced # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # professionals having in-depth computer knowledge. Users are therefore # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # encouraged to load and test the software's suitability as regards their # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # requirements in conditions enabling the security of their systems and/or # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # data to be ensured and, more generally, to use and operate it in the same # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # conditions as regards security. # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # The fact that you are presently reading this means that you have had # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # knowledge of the CeCILL license and that you accept its terms. # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # $Id: FileManager.pm,v 1.7 2018/03/19 13:16:31 doccy Exp $ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # $Log: FileManager.pm,v $ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # Revision 1.7 2018/03/19 13:16:31 doccy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # BugFix: module file was encoded with ISO-8859-1. Switching to UT-8. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # Revision 1.6 2013/11/07 10:19:25 doccy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # Renaming the module. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # Revision 1.5 2013/05/22 11:39:02 doccy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # Update Copyright informations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # Revision 1.4 2013/05/22 10:42:43 doccy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # Add CéCILL Copyright Notice | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # Revision 1.3 2013/05/22 08:11:25 doccy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # Fix POD examples. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # Revision 1.2 2013/05/21 17:04:08 doccy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # Update version. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # Will be automatic from now. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # Revision 1.1.1.1 2013/05/21 16:43:23 doccy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # Perl Module for manage configuration files. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | package Config::FileManager; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # Force having good coding conventions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 3 | ▶ | use 5.010000; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 3 | ▶ | use POSIX; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 3 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 3 | ▶ | use File::HomeDir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 3 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 3 | ▶ | use Text::Patch; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 3 | ▶ | use Text::Diff; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 3 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 3 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 3 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 3 | our $VERSION = (qw$Revision: 1.7 $)[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | ########################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # Plain Old Documentation # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # Name # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # Synopsys # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # Decription 1/2 # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | ########################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | Config::FileManager - Configuration File Management with versionning | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | The Config::FileManager module helps to manage configuration files. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | It provides versionning and check for updates of obsolete | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | versions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | use Config::FileManager; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | The I<Config::FileManager> module: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | =item check wether the user configuration file version is up-to-date | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | =item can propose update taking into account user modifications | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | =item keep (and ca restore) the previous versions of the configuration file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | =item search the configuration file in an ordered list of paths | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | ########################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # Perl # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # Specific Options # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | ########################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 3 | our %default_settings = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # Standard Settings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | "toolname" => undef, # Mandatory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | "version" => undef, # Not mandatory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | "filename" => "config", # Not mandatory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | "paths" => [qw(. __APPDIR__ /usr/local/etc /etc)], # Not mandatory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | "interactive" => 1, # Not mandatory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 3 | our @available_settings = keys %default_settings; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | ########################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # Plain Old Documentation # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # Export Tags # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | ########################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | =head2 EXPORT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | ################# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # Perl # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # Export Tags # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | ################# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # Items to export into callers namespace by default. Note: do not export | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # Do not simply export all your public functions/methods/constants. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 3 | our @EXPORT_OK = (qw()); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 3 | our @EXPORT = qw(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | ################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # Perl Subroutines Implentations # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | ################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | =over 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | =item * the new operator can be given the following parameters: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | =over 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | =item * C<< toolname=<string> >> (mandatory) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | sets the name of the tool the configuration file is designed for. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | =item * C<< version=<string> >> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | sets the current version of the configuration file (can be the same as the tool version). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | =item * C<< filename=<string> >> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | sets the base file name of the configuration file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | =item * C<< paths=[qw(string array of paths)] >> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | sets the ordered list of paths where the configuration file will be searched. The special C<__APPDIR__> is OS dependent and is the user application directory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | =item * C<< interactive=<boolean> >> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | if set to 1, user is asked if some update is available. If set to 0, then update is automatic. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | my $cfg = new Config( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # Mandatory settings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | "toolname" => "tool name", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # Optional settings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | "version" => "version string", # default to undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | "filename" => "config file basename", # default to "config" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | "paths" => [qw(list of/paths /to/look ./for)], # default to [qw(. __APPDIR__ /usr/local/etc /etc)], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | "interactive" => 0, # default to 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 1 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | my %settings = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 1 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 1 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | for my $required (qw(toolname)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | croak "Required parameter '$required' not passed to '$class' constructor" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 1 | ▶ | unless exists $settings{$required}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | $self->{toolname} = $settings{"toolname"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | $self->{filename} = $self->toolname."conf"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # initialize all attributes by passing arguments to accessor methods. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | for my $attrib (keys %settings) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 3 | ▶ | croak "Invalid parameter '$attrib' passed to '$class' constructor" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | unless $self->can($attrib); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 3 | $self->$attrib($settings{$attrib}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # Fill missing settings with default values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | for my $attrib (@available_settings) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 5 | ▶ | $self->$attrib($default_settings{$attrib}) unless defined($settings{$attrib}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | $self->{full_path} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 1 | @{$self->{allVersions}} = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | =item * Method C<toolname> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | This method get/set the name of the tool for which the config file is. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | my $toolname = $cfg->toolname(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | $cfg->toolname("tool name"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 9 | ▶ | sub toolname($;$) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
toolname: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 9 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 1 | my $toolname = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 1 | $self->{toolname} = $toolname; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 1 | $self->{full_path} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 9 | return $self->{toolname}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | =item * Method C<filename> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | This method get/set the file basename of the config file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | my $filename = $cfg->filename(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | $cfg->filename("file name"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 3 | ▶ | sub filename($;$) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
filename: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 3 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 1 | my $filename = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 1 | $self->{filename} = basename $filename; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 1 | $self->{full_path} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 3 | return $self->{filename}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | =item * Method C<paths> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | This method get/set the paths where the config file should be found. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | The special __APPDIR__ path is OS dependant (see I<File::HomeDir> module documentation). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | my @paths = $cfg->paths(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | $cfg->paths(qw(list ./of/paths)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 3 | ▶ | sub paths($;@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
paths: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 3 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 1 | my @p = @{$_[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 1 | @{$self->{paths}} = @p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 1 | $self->{full_path} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 3 | return @{$self->{paths}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | =item * Method C<interactive> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | This method get/set the value of interactive... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | my $v = $cfg->interactive(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | $cfg->interactive(0); # or $cfg->interactive(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 2 | ▶ | sub interactive($;$) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
interactive: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 2 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 1 | my $val = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 1 | $self->{interactive} = $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 2 | return $self->{interactive}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | =item * Method C<version> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | This method get/set the current version of the config file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | my $vers = $cfg->version(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | $cfg->version("0.1.2"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 18 | ▶ | sub version($;$) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 18 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 18 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 3 | my $version = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 3 | $self->{version} = $version; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 3 | @{$self->{allVersions}} = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 18 | return $self->{version}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | =item * Method C<versions> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | This method returns (and prior computes if required) the array of all version's strings from the newest to the oldest. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | $cfg->versions(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 11 | ▶ | sub versions($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
versions: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 11 | ▶ | if (!@{$self->{allVersions}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 2 | my $cur_ver = $self->{version}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 2 | my $old_ver; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 2 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 9 | ▶ | if (ref($cur_ver) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 7 | my @k = keys %{$cur_ver}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 7 | $cur_ver = $k[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 9 | $cur_ver =~ s/^to v//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 9 | push @{$self->{allVersions}}, $cur_ver; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 9 | $old_ver = $cur_ver; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 9 | $cur_ver = $self->{patches}->{"patch from v$old_ver"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | } while (defined($cur_ver)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 11 | return @{$self->{allVersions}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | =item * Method C<defaultContent> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | This method get/set the current default content of the config file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | You can (should) use '__VERSION__' instead of giving it explicitely. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | In such case, it will be replaced by the corresponding version string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | my $cfg_txt = $cfg->defaultContent(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | $cfg->defaultContent("# the default config content of the current version"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 13 | ▶ | sub defaultContent($;$) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
defaultContent: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 13 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 13 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 2 | my $defaultContent = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 2 | $self->{defaultContent} = $defaultContent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 13 | return $self->{defaultContent}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | =item * Method C<addPatch> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | This method adds the patch from a given version of the default config file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | to the preceeding version of the default config. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | $cfg->addPatch( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | "from" => "some version", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | "to" => "previous version", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | "diffs" => ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | @@ -1,1 +0,0 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | -# blablabla | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | '); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 4 | ▶ | sub addPatch($%) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addPatch: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 4 | my %params = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 4 | for my $required (qw(from to diffs)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | croak "Required parameter '$required' not passed to addPatch method." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 12 | ▶ | unless exists $params{$required}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | croak "A patch already exists from version ".$params{"from"}."." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 4 | ▶ | unless !defined($self->{patches}->{"patch from v".$params{"from"}}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 4 | $self->{patches}->{"patch from v".$params{"from"}}{"to v".$params{"to"}}= $params{"diffs"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 4 | @{$self->{allVersions}} = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | =item * Method C<getPath> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | This method gets (and prior computes if required) the path where the config file is. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | If no config file is found, then the default current config file is created in the "correct" place. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | $cfg->getPath(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 11 | ▶ | sub getPath($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getPath: called CC=10 SCAR=24.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 11 | ▶ | return $self->{full_path} if defined($self->{full_path}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | # No config file already defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | # check all given paths in the given order | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 1 | my @p = $self->paths; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 1 | foreach my $path (@p) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | #print "DBG:path=$path\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 1 | ▶ | my $appdir = File::HomeDir->my_dist_data($self->toolname) || ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
'File::HomeDir'->my_dist_data($self->toolname) || ''
MC/DC0%0/1
'File::HomeDir'->my_dist_data($self->toolname) || ''
'File::HomeDir'->my_dist_data($self->toolname)
Truth table50%1/2
A
A= 'File::HomeDir'->my_dist_data($self->toolname)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 1 | $path =~ s/^__APPDIR__$/$appdir/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | #print "DBG:path=$path\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 1 | ▶ | if (-e $path) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 1 | my $full_path = File::Spec->rel2abs(File::Spec->join($path, $self->filename)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 1 | ▶ | if (-e "$full_path") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | $self->{full_path} = $full_path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | return $self->{full_path}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | # No config file found | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | # try to create a config file in all given paths in the given order | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 1 | foreach my $path ($self->paths) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | #print "DBG3:path=$path\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 1 | ▶ | if ($path =~ m/^__APPDIR__$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | my $appdir = File::HomeDir->my_dist_data($self->toolname, { create => 1 }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | $path =~ s/^__APPDIR__$/$appdir/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | #print "DBG4:path=$path\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 1 | ▶ | if (-e $path) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 1 | my $full_path = File::Spec->rel2abs(File::Spec->join($path, $self->filename)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 1 | print "Creation of a default config file for ".$self->toolname.": $full_path\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 1 | my $current_default_config = $self->defaultContent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 1 | $current_default_config =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 1 | $current_default_config =~ s/\s+$/\n/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 1 | my $v = $self->version; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 1 | $current_default_config =~ s/__VERSION__/$v/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 1 | ▶ | open (CFG_FILE, ">".$full_path) or croak "Unable to create config file [".$full_path."]: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 1 | print CFG_FILE $current_default_config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 1 | close(CFG_FILE); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 1 | $self->{full_path} = $full_path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 1 | return $self->{full_path}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | =item * Method C<update> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | This method check if the current config file is up-to-date and proposes an update if it is not. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | The update tries to preserve custom user's settings. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | $cfg->update(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 1 | ▶ | sub update($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: called CC=17 SCAR=36.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | # Check if config file is up-to-date | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 1 | ▶ | open (CFG_FILE, "<".$self->getPath) or croak "Unable to open config file [".$self->getPath."]: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 1 | my @versions = $self->versions; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 1 | my $current_user_config_version = $versions[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 1 | my $current_user_config = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 1 | ▶ | while (<CFG_FILE>) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 7 | $current_user_config .= $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 7 | ▶ | if (/^#.*configuration file (\d+.\d+.\d+.*)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 1 | $current_user_config_version = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 1 | close(CFG_FILE); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | #print "*** Current user use config file version $current_user_config_version:\n$current_user_config*** EOF\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 1 | ▶ | if ($current_user_config_version ne $self->version) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 1 | my $diffs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 1 | print "Your configuration file [".$self->getPath."] is not up-to-date!\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | # Computing original corresponding version file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 1 | my $old_default_config = $self->getDefaultContent($current_user_config_version); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 1 | $old_default_config =~ s/$current_user_config_version/__VERSION__/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | # Diffing original corresponding version file with potentially modified file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 1 | $current_user_config =~ s/$current_user_config_version/__VERSION__/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 1 | $diffs = diff(\$old_default_config, \$current_user_config, { STYLE => 'OldStyle' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 1 | ▶ | if ($diffs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | #print "*** Diffs between corresponding obsolete default version:\n$diffs*** END\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | # Trying to apply these diffs to up-to-date version... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 1 | $current_user_config = patch($self->defaultContent, $diffs, { STYLE => 'OldStyle' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | #print "DBG:::\n".$self->getDefaultContent."DBG:::\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | $current_user_config = $self->getDefaultContent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | my $v = $self->version; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | $current_user_config =~ s/__VERSION__/$v/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | $_ = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 1 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | #print "Unable to automatically propose an update for this file\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 1 | $current_user_config = $self->getDefaultContent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 1 | my $v = $self->version; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 1 | $current_user_config =~ s/__VERSION__/$v/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | #print "*** diff between v. $current_user_config_version and ".$self->version." ***\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 1 | print diff($self->getPath, \$current_user_config, { STYLE => "Table", FILENAME_B => "Proposed Up-to-date config file"}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 1 | my $answer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 1 | ▶ | if ($self->interactive) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | ▶ | print "Do you want to upgrade your configuration file [".($diffs ? "y/N" : "Y/n")."] ? "; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | $answer = <STDIN>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 1 | $answer = "Y\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 1 | ▶ | if (($answer eq "Y\n") or ($answer eq "y\n") or (!$diffs and ($answer eq "\n"))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition22%2/9
$answer eq "Y\n" or $answer eq "y\n" or not $diffs and $answer eq "\n"
$answer eq "Y\n" or $answer eq "y\n"
not $diffs and $answer eq "\n"
MC/DC0%0/4
$answer eq "Y\n" or $answer eq "y\n" or not $diffs and $answer eq "\n"
$answer eq "Y\n"
$answer eq "y\n"
not $diffs
$answer eq "\n"
Truth table20%1/5
A or B or not(C) and D
A= $answer eq "Y\n"B= $answer eq "y\n"C= not $diffsD= $answer eq "\n"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 1 | print "Upgrading the config file for ".$self->toolname.": ".$self->getPath."\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 1 | ▶ | open (CFG_FILE, ">".$self->getPath) or croak "Unable to create config file [".$self->getPath."]: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 1 | print CFG_FILE $current_user_config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 1 | close(CFG_FILE); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | ▶ | if ($self->interactive) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | print "Do you want to continue [y/N] ? "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | $answer = <STDIN>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | $answer = "Y\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | ▶ | exit 0 unless (($answer eq "Y\n") or ($answer eq "y\n")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$answer eq "Y\n" or $answer eq "y\n"
MC/DC0%0/2
$answer eq "Y\n" or $answer eq "y\n"
$answer eq "Y\n"
$answer eq "y\n"
Truth table0%0/3
A or B
A= $answer eq "Y\n"B= $answer eq "y\n"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | #print "*** End of diff between v. $current_user_config_version and ".$self->version." ***\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | =item * Method C<getDefaultContent> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | This method gets the default config content of the given version. If ommited, then uses the current version. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | $cfg->getDefaultContent(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | $cfg->getDefaultContent("a given version"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 9 | ▶ | sub getDefaultContent($;$) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getDefaultContent: called CC=12 SCAR=25.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 9 | ▶ | my $wanted_version = shift || $self->version; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
shift() || $self->version
MC/DC0%0/2
shift() || $self->version
shift()
$self->version
Truth table66%2/3
A || B
A= shift()B= $self->version
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 9 | my $computed_version = $self->version; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 9 | my $computed_config = $self->defaultContent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 9 | $computed_config =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 9 | $computed_config =~ s/\s+$/\n/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 9 | my $error = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | # print "looking for version $wanted_version\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 9 | ▶ | if (!grep(/^$wanted_version$/, $self->versions)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | # print "not a valid version\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | $error = "version '$wanted_version' is not valid."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | # print "against $computed_version\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 9 | ▶ | while (!defined($error) && ($computed_version ne $wanted_version)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $error and $computed_version ne $wanted_version
MC/DC50%1/2
not defined $error and $computed_version ne $wanted_version
not defined $error
$computed_version ne $wanted_version
Truth table66%2/3
not(A) and B
A= not defined $errorB= $computed_version ne $wanted_version
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 8 | $error = "Unable to find a patch from version '$computed_version'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | # print "looking keys of patches\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 8 | foreach my $k (keys %{$self->{patches}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | # print "looking key '$k' against 'patch from v$computed_version'\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 22 | ▶ | if ($k =~ /^patch from v$computed_version$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | # print "Found!!!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 8 | my $previous_version; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | my $str; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 8 | $error = "Unable to find a patch to version '$wanted_version'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 8 | foreach my $kk (keys %{$self->{patches}->{$k}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | # print "looking sub key '$kk'\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 8 | ▶ | if ($kk =~ /^to v(.*)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | # print "Found again!!!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 8 | $previous_version = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 8 | $str = $self->{patches}->{$k}->{$kk}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 8 | $str =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 8 | $str =~ s/\s+$/\n/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 8 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 8 | ▶ | if (defined($str) && defined($previous_version)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $str and defined $previous_version
MC/DC0%0/2
defined $str and defined $previous_version
defined $str
defined $previous_version
Truth table33%1/3
A and B
A= defined $strB= defined $previous_version
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | # print "\n============\n\n*** $k ***\n$str*** end $k ***\n\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | # print "*** applying patch to v$computed_version would give v$previous_version ***\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 8 | $error = "Unable to apply the patch from version v$computed_version to v$previous_version\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 8 | $computed_config = patch($computed_config, $str, { STYLE => 'Unified' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | # print "$computed_config*** end of patch from v$computed_version to v$previous_version ***\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 8 | $computed_version = $previous_version; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 8 | $error = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 8 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 9 | $computed_config =~ s/__VERSION__/$computed_version/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 9 | !defined($error); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 9 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | croak $error."\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | $computed_version = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | $computed_config = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 9 | return $computed_config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | ############################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | # End of this Perl Module # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | ############################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | ########################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | # Plain Old Documentation # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | # Authors # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | # Copyright and License # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | ########################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | Alban MANCHERON E<lt>L<alban.mancheron@lirmm.fr|mailto:alban.mancheron@lirmm.fr>E<gt>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | Nicolas PHILIPPE E<lt>L<nicolas.philippe@inserm.fr|mailto:nicolas.philippe@inserm.fr>E<gt>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | Copyright (C) 2012-2013 -- LIRMM/UM2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | (Laboratoire d'Informatique, de Robotique et de | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | Microélectronique de Montpellier / | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | Université de Montpellier 2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | IRB/INSERM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | (Institut de Recherche en Biothérapie / | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | Institut National de la Santé et de la | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | Recherche Médicale) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | =head2 FRENCH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | Ce fichier fait partie du Pipeline de traitement de données NGS de la | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | plateforme ATGC labélisée par le GiS IBiSA. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | Ce logiciel est régi par la licence CeCILL soumise au droit français et | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | respectant les principes de diffusion des logiciels libres. Vous pouvez | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | utiliser, modifier et/ou redistribuer ce programme sous les conditions de | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA sur | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | le site "http://www.cecill.info". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | =head2 ENGLISH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | This File is part of the NGS data processing Pipeline of the ATGC | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | accredited by the IBiSA GiS. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | This software is governed by the CeCILL license under French law and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | abiding by the rules of distribution of free software. You can use, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | modify and/ or redistribute the software under the terms of the CeCILL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | license as circulated by CEA, CNRS and INRIA at the following URL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | "http://www.cecill.info". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | ############## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | # End of POD # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | ############## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||