« blib/lib/Config/Model/models/Itself/CargoElement.pl
↑ Summary
blib/lib/Config/Model/models/Itself/CommonElement.pl »
| 1 | 1 | ▶ | # |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | 1 | ▶ | # This file is part of Config-Model-Itself |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | # | |
| 4 | # This software is Copyright (c) 2007-2026 by Dominique Dumont. | ||
| 5 | # | ||
| 6 | # This is free software, licensed under: | ||
| 7 | # | ||
| 8 | # The GNU Lesser General Public License, Version 2.1, February 1999 | ||
| 9 | # | ||
| 10 | # Copyright (c) 2007-2015 Dominique Dumont. | ||
| 11 | # | ||
| 12 | # This file is part of Config-Model-Itself. | ||
| 13 | # | ||
| 14 | # Config-Model-Itself is free software; you can redistribute it | ||
| 15 | # and/or modify it under the terms of the GNU Lesser Public License | ||
| 16 | # as published by the Free Software Foundation; either version 2.1 | ||
| 17 | # of the License, or (at your option) any later version. | ||
| 18 | # | ||
| 19 | # Config-Model-Itself is distributed in the hope that it will be | ||
| 20 | # useful, but WITHOUT ANY WARRANTY; without even the implied | ||
| 21 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
| 22 | # See the GNU Lesser Public License for more details. | ||
| 23 | # | ||
| 24 | # You should have received a copy of the GNU Lesser Public License | ||
| 25 | # along with Config-Model-Itself; if not, write to the Free Software | ||
| 26 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
| 27 | |||
| 28 | 11 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 29 | 11 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 30 | |||
| 31 | return [ | ||
| 32 | [ | ||
| 33 | 7 | name => "Itself::Class", | |
| 34 | author => 'Dominique Dumont', | ||
| 35 | copyright => '2007-2011 Dominique Dumont.', | ||
| 36 | license => 'LGPL-2', | ||
| 37 | |||
| 38 | class_description => | ||
| 39 | "Configuration class. This class represents a node of a configuration tree.", | ||
| 40 | |||
| 41 | 'element' => [ | ||
| 42 | |||
| 43 | [qw/class_description license gist/] => { | ||
| 44 | type => 'leaf', | ||
| 45 | value_type => 'string', | ||
| 46 | }, | ||
| 47 | |||
| 48 | [qw/author copyright/] => { | ||
| 49 | type => 'list', | ||
| 50 | cargo => { | ||
| 51 | type => 'leaf', | ||
| 52 | value_type => 'uniline', | ||
| 53 | } | ||
| 54 | }, | ||
| 55 | |||
| 56 | 'class' => { | ||
| 57 | type => 'leaf', | ||
| 58 | value_type => 'uniline', | ||
| 59 | summary => "Override implementation of configuration node", | ||
| 60 | description => | ||
| 61 | "Perl class name used to override the default implementation of a configuration node. " | ||
| 62 | ."This Perl class must inherit L<Config::Model::Node>. Use with care.", | ||
| 63 | assert => { | ||
| 64 | "1_load_class" => { | ||
| 65 | code => 'return 1 unless defined $_;' | ||
| 66 | .'return Mouse::Util::load_class($_);', | ||
| 67 | msg => 'Error while loading $_ class ', | ||
| 68 | }, | ||
| 69 | "2_class_inherit" => { | ||
| 70 | code => 'not defined $_ or $_->isa("Config::Model::Node")', | ||
| 71 | msg => 'class $_ must inherit Config::Model::Node', | ||
| 72 | } | ||
| 73 | }, | ||
| 74 | |||
| 75 | }, | ||
| 76 | |||
| 77 | 'element' => { | ||
| 78 | type => 'hash', | ||
| 79 | level => 'important', | ||
| 80 | ordered => 1, | ||
| 81 | index_type => 'string', | ||
| 82 | cargo => { | ||
| 83 | type => 'node', | ||
| 84 | config_class_name => 'Itself::Element', | ||
| 85 | }, | ||
| 86 | }, | ||
| 87 | |||
| 88 | [qw/include include_backend/] => { | ||
| 89 | type => 'list', | ||
| 90 | cargo => { | ||
| 91 | type => 'leaf', | ||
| 92 | value_type => 'reference', | ||
| 93 | refer_to => '! class', | ||
| 94 | } | ||
| 95 | }, | ||
| 96 | |||
| 97 | 'include_after' => { | ||
| 98 | type => 'leaf', | ||
| 99 | value_type => 'reference', | ||
| 100 | refer_to => '- element', | ||
| 101 | }, | ||
| 102 | |||
| 103 | generated_by => { | ||
| 104 | type => 'leaf', | ||
| 105 | value_type => 'uniline', | ||
| 106 | }, | ||
| 107 | |||
| 108 | rw_config => { | ||
| 109 | type => 'node', | ||
| 110 | config_class_name => 'Itself::ConfigReadWrite', | ||
| 111 | }, | ||
| 112 | |||
| 113 | 'accept' => { | ||
| 114 | type => 'hash', | ||
| 115 | index_type => 'string', | ||
| 116 | ordered => 1, | ||
| 117 | cargo => { | ||
| 118 | type => 'node', | ||
| 119 | config_class_name => 'Itself::ConfigAccept', | ||
| 120 | }, | ||
| 121 | }, | ||
| 122 | ], | ||
| 123 | 'description' => [ | ||
| 124 | element => "Specify the elements names of this configuration class.", | ||
| 125 | gist => 'String used to construct a summary of the content of a node. This ' | ||
| 126 | .'parameter is used by user interface to show users the gist of the ' | ||
| 127 | .'content of this node. This parameter has no other effect. This string ' | ||
| 128 | .'may contain element values in the form "C<{foo} or {bar}>". When ' | ||
| 129 | .'constructing the gist, C<{foo}> is replaced by the value of element ' | ||
| 130 | .'C<foo>. Likewise for C<{bar}>.', | ||
| 131 | include => "Include the element description of another class into this class.", | ||
| 132 | include_after => "insert the included elements after a specific element. " | ||
| 133 | . "By default, included elements are placed before all other elements.", | ||
| 134 | include_backend => "Include the read/write specification of another class into this class.", | ||
| 135 | class_description => "Explain the purpose of this configuration class. This description is re-used to generate the documentation of your configuration class. You can use pod markup to format your description. See L<perlpod> for details.", | ||
| 136 | rw_config => "Specify the backend used to read and write configuration data. See L<Config::Model::BackendMgr> for details", | ||
| 137 | generated_by => "When set, this class was generated by some program. You should not edit " | ||
| 138 | ."this class as your modifications may be clobbered later on when the class is regenerated.", | ||
| 139 | accept => "Specifies names of the elements this configuration class accepts as valid. " | ||
| 140 | ."The key of the hash is a regular expression that are be tested against | ||
| 141 | candidate parameters. When the parameter matches the regular expression, | ||
| 142 | a new parameter is created in the model using the description provided | ||
| 143 | in the value of this hash key. Note that the regexp must match the whole name | ||
| 144 | of the potential parameter. I.e. the specified regexp is eval\'ed | ||
| 145 | with a leading C<^> and a trailing C<\$>." | ||
| 146 | ], | ||
| 147 | ], | ||
| 148 | |||
| 149 | [ | ||
| 150 | name => 'Itself::ConfigReadWrite::DefaultLayer', | ||
| 151 | |||
| 152 | 'element' => [ | ||
| 153 | 'config_dir' => { | ||
| 154 | type => 'leaf', | ||
| 155 | value_type => 'uniline', | ||
| 156 | level => 'normal', | ||
| 157 | }, | ||
| 158 | |||
| 159 | os_config_dir => { | ||
| 160 | type => 'hash', | ||
| 161 | index_type => 'string', | ||
| 162 | cargo => { | ||
| 163 | type => 'leaf', | ||
| 164 | value_type => 'uniline', | ||
| 165 | }, | ||
| 166 | summary => 'configuration file directory for specific OS', | ||
| 167 | description => 'Specify and alternate location of a configuration directory depending ' | ||
| 168 | .q!on the OS (as returned by C<$^O> or C<$Config{'osname'}>, see L<perlport/PLATFORMS>) ! | ||
| 169 | .q!Common values for C<$^O> are 'linux', 'MSWin32', 'darwin'! | ||
| 170 | }, | ||
| 171 | 'file' => { | ||
| 172 | type => 'leaf', | ||
| 173 | value_type => 'uniline', | ||
| 174 | level => 'normal', | ||
| 175 | summary => 'target configuration file name', | ||
| 176 | description => 'specify the configuration file name. This parameter may ' | ||
| 177 | .'not be applicable depending on your application. It may also be ' | ||
| 178 | .'hardcoded in a custom backend. If not specified, the instance name ' | ||
| 179 | .'is used as base name for your configuration file. The configuration file name' | ||
| 180 | .'can be specified with &index() or &element function. See ' | ||
| 181 | .'L<backend specifications|http://search.cpan.org/dist/Config-Model/lib/Config/Model/BackendMgr.pm#Backend_specification> ' | ||
| 182 | .'and L<Config::Model::Role::ComputeFunction>.' | ||
| 183 | }, | ||
| 184 | ] | ||
| 185 | ], | ||
| 186 | |||
| 187 | [ | ||
| 188 | name => "Itself::ConfigReadWrite", | ||
| 189 | include => "Itself::ConfigReadWrite::DefaultLayer", | ||
| 190 | include_after => 'backend', | ||
| 191 | |||
| 192 | 'element' => [ | ||
| 193 | |||
| 194 | 'backend' => { | ||
| 195 | type => 'leaf', | ||
| 196 | class => 'Config::Model::Itself::BackendDetector', | ||
| 197 | value_type => 'enum', | ||
| 198 | choice => [qw/cds_file perl_file custom/], | ||
| 199 | warn_if_match => { | ||
| 200 | '^custom$' => { | ||
| 201 | msg => "custom backend are deprecated" | ||
| 202 | } | ||
| 203 | }, | ||
| 204 | replace => { | ||
| 205 | perl => 'perl_file', | ||
| 206 | ini => 'IniFile', | ||
| 207 | ini_file => 'IniFile', | ||
| 208 | cds => 'cds_file', | ||
| 209 | }, | ||
| 210 | description => 'specifies the backend to store permanently configuration data.', | ||
| 211 | help => { | ||
| 212 | cds_file => "file with config data string. This is Config::Model own serialisation format, designed to be compact and readable. Configuration filename is made with instance name", | ||
| 213 | IniFile => | ||
| 214 | "Ini file format. Beware that the structure of your model must match the limitations of the INI file format, i.e only a 2 levels hierarchy. Configuration filename is made with instance name", | ||
| 215 | perl_file => | ||
| 216 | "file with a perl data structure. Configuration filename is made with instance name", | ||
| 217 | custom => "deprecated", | ||
| 218 | } | ||
| 219 | }, | ||
| 220 | |||
| 221 | 'function' => { | ||
| 222 | type => 'leaf', | ||
| 223 | value_type => 'uniline', | ||
| 224 | status => 'deprecated', | ||
| 225 | level => 'hidden', | ||
| 226 | warp => { | ||
| 227 | follow => '- backend', | ||
| 228 | rules => [ | ||
| 229 | custom => { | ||
| 230 | level => 'normal', | ||
| 231 | upstream_default => 'read', | ||
| 232 | } | ||
| 233 | ], | ||
| 234 | } | ||
| 235 | }, | ||
| 236 | |||
| 237 | 'auto_create' => { | ||
| 238 | type => 'leaf', | ||
| 239 | value_type => 'boolean', | ||
| 240 | level => 'normal', | ||
| 241 | upstream_default => 0, | ||
| 242 | summary => 'Creates configuration files as needed', | ||
| 243 | }, | ||
| 244 | |||
| 245 | yaml_class => { | ||
| 246 | type => 'leaf', | ||
| 247 | value_type => 'uniline', | ||
| 248 | level => 'hidden', | ||
| 249 | description => 'Specify the YAML class that is used to load and dump YAML files.' | ||
| 250 | .' Defaults to L<YAML::Tiny>.' | ||
| 251 | .' See L<yaml_class doc|Config::Model::Backend::Yaml/yaml_class> for details on ' | ||
| 252 | .' why another YAML class can suit your configuration file needs.', | ||
| 253 | upstream_default => 'YAML::Tiny', | ||
| 254 | warp => { | ||
| 255 | follow => '- backend', | ||
| 256 | rules => [ Yaml => { level => 'normal', } ], | ||
| 257 | } | ||
| 258 | }, | ||
| 259 | |||
| 260 | file_mode => { | ||
| 261 | type => 'leaf', | ||
| 262 | value_type => 'uniline', | ||
| 263 | level => 'normal', | ||
| 264 | summary => 'configuration file mode', | ||
| 265 | description => 'specify the configuration file mode. C<file_mode> parameter can be used to set the ' | ||
| 266 | . 'mode of the written file. C<file_mode> value can be in any form supported by L<Path::Tiny/chmod>.' | ||
| 267 | }, | ||
| 268 | |||
| 269 | default_layer => { | ||
| 270 | type => 'node', | ||
| 271 | config_class_name => 'Itself::ConfigReadWrite::DefaultLayer', | ||
| 272 | summary => q!How to find default values in a global config file!, | ||
| 273 | description => q!Specifies where to find a global configuration file that ! | ||
| 274 | .q!specifies default values. For instance, this is used by OpenSSH to ! | ||
| 275 | .q!specify a global configuration file (C</etc/ssh/ssh_config>) that is ! | ||
| 276 | .q!overridden by user's file!, | ||
| 277 | }, | ||
| 278 | |||
| 279 | 'class' => { | ||
| 280 | type => 'leaf', | ||
| 281 | value_type => 'uniline', | ||
| 282 | level => 'hidden', | ||
| 283 | warp => { | ||
| 284 | follow => '- backend', | ||
| 285 | rules => [ | ||
| 286 | custom => { | ||
| 287 | level => 'normal', | ||
| 288 | mandatory => 1, | ||
| 289 | } | ||
| 290 | ], | ||
| 291 | } | ||
| 292 | }, | ||
| 293 | |||
| 294 | 'store_class_in_hash' => { | ||
| 295 | type => 'leaf', | ||
| 296 | value_type => 'uniline', | ||
| 297 | level => 'hidden', | ||
| 298 | description => 'Specify element hash name that contains all INI classes. ' | ||
| 299 | .'See L<Config::Model::Backend::IniFile/"Arbitrary class name">', | ||
| 300 | warp => { | ||
| 301 | follow => '- backend', | ||
| 302 | rules => [ IniFile => { level => 'normal', } ], | ||
| 303 | } | ||
| 304 | }, | ||
| 305 | |||
| 306 | 'section_map' => { | ||
| 307 | type => 'hash', | ||
| 308 | level => 'hidden', | ||
| 309 | index_type => 'string', | ||
| 310 | description => 'Specify element name that contains one INI class. E.g. to store ' | ||
| 311 | .'INI class [foo] in element Foo, specify { foo => "Foo" } ', | ||
| 312 | warp => { | ||
| 313 | follow => '- backend', | ||
| 314 | rules => [ IniFile => { level => 'normal', } ], | ||
| 315 | }, | ||
| 316 | cargo => { | ||
| 317 | type => 'leaf', | ||
| 318 | value_type => 'uniline', | ||
| 319 | }, | ||
| 320 | }, | ||
| 321 | |||
| 322 | ['split_list_value','split_check_list_value'] => { | ||
| 323 | type => 'leaf', | ||
| 324 | value_type => 'uniline', | ||
| 325 | level => 'hidden', | ||
| 326 | description => 'Regexp to split the value read from ini file. Usually "\s+" or "[,\s]"', | ||
| 327 | warp => { | ||
| 328 | follow => '- backend', | ||
| 329 | rules => [ IniFile => { level => 'normal', } ], | ||
| 330 | } | ||
| 331 | }, | ||
| 332 | |||
| 333 | assign_char => { | ||
| 334 | type => 'leaf', | ||
| 335 | value_type => 'uniline', | ||
| 336 | level => 'hidden', | ||
| 337 | description => 'Character used to assign value in INI file. Default is C<=>. ' | ||
| 338 | .'See L<details|Config::Model::Backend::IniFile/"Handle key value files">', | ||
| 339 | upstream_default => '#', | ||
| 340 | warp => { | ||
| 341 | follow => '- backend', | ||
| 342 | rules => [ IniFile => { level => 'normal', } ], | ||
| 343 | } | ||
| 344 | }, | ||
| 345 | |||
| 346 | assign_with => { | ||
| 347 | type => 'leaf', | ||
| 348 | value_type => 'uniline', | ||
| 349 | level => 'hidden', | ||
| 350 | description => 'String used write assignment in INI file. Default is "C< = >". ' | ||
| 351 | .'See L<details|Config::Model::Backend::IniFile/"Handle key value files">', | ||
| 352 | upstream_default => '#', | ||
| 353 | warp => { | ||
| 354 | follow => '- backend', | ||
| 355 | rules => [ IniFile => { level => 'normal', } ], | ||
| 356 | } | ||
| 357 | }, | ||
| 358 | |||
| 359 | ['join_list_value', 'join_check_list_value'] => { | ||
| 360 | type => 'leaf', | ||
| 361 | value_type => 'uniline', | ||
| 362 | level => 'hidden', | ||
| 363 | warp => { | ||
| 364 | follow => '- backend', | ||
| 365 | rules => [ IniFile => { level => 'normal', } ], | ||
| 366 | } | ||
| 367 | }, | ||
| 368 | |||
| 369 | 'write_boolean_as' => { | ||
| 370 | type => 'list', | ||
| 371 | description => 'Specify how to write a boolean value in config file. Suggested values are ' | ||
| 372 | . '"no","yes". ', | ||
| 373 | max_index => 1, | ||
| 374 | cargo => { | ||
| 375 | type => 'leaf', | ||
| 376 | value_type => 'uniline', | ||
| 377 | }, | ||
| 378 | }, | ||
| 379 | |||
| 380 | force_lc_section => { | ||
| 381 | type => 'leaf', | ||
| 382 | value_type => 'boolean', | ||
| 383 | level => 'hidden', | ||
| 384 | upstream_default => 0, | ||
| 385 | description => "force section to be lowercase", | ||
| 386 | warp => { | ||
| 387 | follow => '- backend', | ||
| 388 | rules => [ IniFile => { level => 'normal', } ], | ||
| 389 | } | ||
| 390 | }, | ||
| 391 | force_lc_key => { | ||
| 392 | type => 'leaf', | ||
| 393 | value_type => 'boolean', | ||
| 394 | level => 'hidden', | ||
| 395 | upstream_default => 0, | ||
| 396 | description => "force key names to be lowercase", | ||
| 397 | warp => { | ||
| 398 | follow => '- backend', | ||
| 399 | rules => [ IniFile => { level => 'normal', } ], | ||
| 400 | } | ||
| 401 | }, | ||
| 402 | force_lc_value => { | ||
| 403 | type => 'leaf', | ||
| 404 | value_type => 'boolean', | ||
| 405 | level => 'hidden', | ||
| 406 | upstream_default => 0, | ||
| 407 | description => "force values to be lowercase", | ||
| 408 | warp => { | ||
| 409 | follow => '- backend', | ||
| 410 | rules => [ IniFile => { level => 'normal', } ], | ||
| 411 | } | ||
| 412 | }, | ||
| 413 | |||
| 414 | 'full_dump' => { | ||
| 415 | type => 'leaf', | ||
| 416 | value_type => 'boolean', | ||
| 417 | level => 'hidden', | ||
| 418 | description => 'Also dump default values in the data structure. Useful if the dumped configuration data will be used by the application. (default is yes)', | ||
| 419 | upstream_default => '1', | ||
| 420 | warp => { | ||
| 421 | follow => { backend => '- backend' }, | ||
| 422 | rules => [ '$backend =~ /yaml|perl/i' => { level => 'normal', } ], | ||
| 423 | } | ||
| 424 | }, | ||
| 425 | |||
| 426 | 'comment_delimiter' => { | ||
| 427 | type => 'leaf', | ||
| 428 | value_type => 'uniline', | ||
| 429 | level => 'hidden', | ||
| 430 | description => 'list of characters that start a comment. When more that one character' | ||
| 431 | .' is used. the first one is used to write back comment. For instance,' | ||
| 432 | .' value "#;" indicate that a comments can start with "#" or ";" and that all comments' | ||
| 433 | .' are written back with "#".', | ||
| 434 | upstream_default => '#', | ||
| 435 | warp => { | ||
| 436 | follow => '- backend', | ||
| 437 | rules => [ IniFile => { level => 'normal', } ], | ||
| 438 | } | ||
| 439 | }, | ||
| 440 | |||
| 441 | quote_value => { | ||
| 442 | type => 'leaf', | ||
| 443 | value_type => 'enum', | ||
| 444 | choice => ['shell_style'], | ||
| 445 | level => 'hidden', | ||
| 446 | description => 'Specify how to handle quoted values. By default, quoted values ' | ||
| 447 | .'are left as is. With C<shell_style>, value are parsed and unquoted like in a shell. ' | ||
| 448 | .'Values containing a space are written back with double quotes.', | ||
| 449 | warp => { | ||
| 450 | follow => '- backend', | ||
| 451 | rules => [ IniFile => { level => 'normal', } ], | ||
| 452 | } | ||
| 453 | }, | ||
| 454 | |||
| 455 | 'auto_delete' => { | ||
| 456 | type => 'leaf', | ||
| 457 | value_type => 'boolean', | ||
| 458 | level => 'normal', | ||
| 459 | upstream_default => 0, | ||
| 460 | summary => 'Delete empty configuration file', | ||
| 461 | description => 'Delete configuration files when no information is left in there.' | ||
| 462 | . ' This may happen when data is removed by user. This is mostly useful when the ' | ||
| 463 | . ' configuration of an application is made of several files.', | ||
| 464 | }, | ||
| 465 | |||
| 466 | ], | ||
| 467 | description => [ | ||
| 468 | join_list_value => 'string to join list values before writing the entry in ini file. Usually " " or ", "', | ||
| 469 | join_check_list_value => 'string to join checked items names before writing the entry in the ini file. Usually " " or ", "', | ||
| 470 | ], | ||
| 471 | |||
| 472 | ], | ||
| 473 | |||
| 474 | [ | ||
| 475 | name => 'Itself::ConfigAccept', | ||
| 476 | |||
| 477 | include => "Itself::Element", | ||
| 478 | include_after => 'accept_after', | ||
| 479 | 'element' => [ | ||
| 480 | 'name_match' => { | ||
| 481 | type => 'leaf', | ||
| 482 | value_type => 'uniline', | ||
| 483 | upstream_default => '.*', | ||
| 484 | status => 'deprecated', | ||
| 485 | }, | ||
| 486 | 'accept_after' => { | ||
| 487 | type => 'leaf', | ||
| 488 | value_type => 'reference' , | ||
| 489 | refer_to => '- - element' , | ||
| 490 | description => 'specify where to insert accepted element. This does' | ||
| 491 | . ' not change the behavior and helps generating more consistent ' | ||
| 492 | . ' user interfaces' | ||
| 493 | } | ||
| 494 | |||
| 495 | ], | ||
| 496 | ], | ||
| 497 | |||
| 498 | ]; | ||