Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 03-May-2022 | - | ||||
calc/etc/ | H | 01-May-2018 | - | 15 | 12 | |
etc/ | H | 01-May-2018 | - | 49 | 39 | |
lib/MooX/ | H | 01-May-2018 | - | 899 | 231 | |
t/ | H | 01-May-2018 | - | 818 | 648 | |
ARTISTIC-1.0 | H A D | 05-Dec-2014 | 6.2 KiB | 131 | 99 | |
Changes | H A D | 01-May-2018 | 2.1 KiB | 61 | 51 | |
GPL-1 | H A D | 12-Dec-2014 | 12.3 KiB | 253 | 200 | |
LICENSE | H A D | 16-Dec-2014 | 667 | 17 | 12 | |
MANIFEST | H A D | 01-May-2018 | 1.1 KiB | 42 | 41 | |
MANIFEST.SKIP | H A D | 30-Apr-2018 | 348 | 36 | 35 | |
META.json | H A D | 01-May-2018 | 2.5 KiB | 92 | 91 | |
META.yml | H A D | 01-May-2018 | 1 KiB | 39 | 38 | |
Makefile.PL | H A D | 23-Apr-2018 | 5 KiB | 141 | 128 | |
README.md | H A D | 01-May-2018 | 6.1 KiB | 180 | 105 |
README.md
1# NAME 2 3MooX::ConfigFromFile - Moo eXtension for initializing objects from config file 4 5<div> 6 <a href="https://travis-ci.org/perl5-utils/MooX-ConfigFromFile"><img src="https://travis-ci.org/perl5-utils/MooX-ConfigFromFile.svg?branch=master" alt="Travis CI"/></a> 7 <a href='https://coveralls.io/github/perl5-utils/MooX-ConfigFromFile?branch=master'><img src='https://coveralls.io/repos/github/perl5-utils/MooX-ConfigFromFile/badge.svg?branch=master' alt='Coverage Status'/></a> 8</div> 9 10# SYNOPSIS 11 12 package Role::Action; 13 14 use Moo::Role; 15 16 has operator => ( is => "ro" ); 17 18 package Action; 19 20 use Moo; 21 use MooX::ConfigFromFile; # imports the MooX::ConfigFromFile::Role 22 23 with "Role::Action"; 24 25 sub operate { return say shift->operator; } 26 27 package OtherAction; 28 29 use Moo; 30 31 with "Role::Action", "MooX::ConfigFromFile::Role"; 32 33 sub operate { return warn shift->operator; } 34 35 package QuiteOtherOne; 36 37 use Moo; 38 39 # consumes the MooX::ConfigFromFile::Role but load config only once 40 use MooX::ConfigFromFile config_singleton => 1; 41 42 with "Role::Action"; 43 44 sub _build_config_prefix { "die" } 45 46 sub operate { return die shift->operator; } 47 48 package main; 49 50 my $action = Action->new(); # tries to find a config file in config_dirs and loads it 51 my $other = OtherAction->new( config_prefix => "warn" ); # use another config file 52 my $quite_o = QuiteOtherOne->new(); # quite another way to have an individual config file 53 54# DESCRIPTION 55 56This module is intended to easy load initialization values for attributes 57on object construction from an appropriate config file. The building is 58done in [MooX::ConfigFromFile::Role](https://metacpan.org/pod/MooX::ConfigFromFile::Role) - using MooX::ConfigFromFile ensures 59the role is applied. 60 61For easier usage, with 0.004, several options can be passed via _use_ resulting 62in default initializers for appropriate role attributes: 63 64- `config_prefix` 65 66 Default for ["config\_prefix" in MooX::ConfigFromFile::Role](https://metacpan.org/pod/MooX::ConfigFromFile::Role#config_prefix). 67 68- `config_prefixes` 69 70 Default for ["config\_prefixes" in MooX::ConfigFromFile::Role](https://metacpan.org/pod/MooX::ConfigFromFile::Role#config_prefixes). Ensure when use 71 this flag together with [MooX::Cmd](https://metacpan.org/pod/MooX::Cmd) to load `MooX::ConfigFromFile` before 72 `MooX::Cmd`. 73 74- `config_prefix_map_separator` 75 76 Default for ["config\_prefix\_map\_separator" in MooX::ConfigFromFile::Role](https://metacpan.org/pod/MooX::ConfigFromFile::Role#config_prefix_map_separator). 77 78 package Foo; 79 80 # apply role MooX::ConfigFromFile::Role and override default for 81 # attribute config_prefix_map_separator 82 use MooX::ConfigFromFile config_prefix_map_separator => "~"; 83 84 ... 85 86- `config_extensions` 87 88 Default for ["config\_extensions" in MooX::ConfigFromFile::Role](https://metacpan.org/pod/MooX::ConfigFromFile::Role#config_extensions). 89 90- `config_dirs` 91 92 Default for ["config\_dirs" in MooX::ConfigFromFile::Role](https://metacpan.org/pod/MooX::ConfigFromFile::Role#config_dirs). 93 Same warning regarding modifying this attribute applies here: 94 Possible, but use with caution! 95 96 package Foo; 97 98 use MooX::ConfigFromFile config_dirs => [qw(/opt/foo/etc /home/alfred/area/foo/etc)]; 99 100 ... 101 102- `config_files` 103 104 Default for ["config\_files" in MooX::ConfigFromFile::Role](https://metacpan.org/pod/MooX::ConfigFromFile::Role#config_files). 105 106 Reasonable when you want exactly one config file in development mode. 107 For production code it is highly recommended to override the builder. 108 109- `config_singleton` 110 111 Flag adding a wrapper [around](https://metacpan.org/pod/Class::Method::Modifiers#around-method-s-sub) 112 the _builder_ of ["loaded\_config" in MooX::ConfigFromFile::Role](https://metacpan.org/pod/MooX::ConfigFromFile::Role#loaded_config) to ensure a 113 config is loaded only once per class. The _per class_ restriction results 114 from applicable modifiers per class (and singletons are per class). 115 116- `config_identifier` 117 118 Default for ["config\_identifier" in MooX::File::ConfigDir](https://metacpan.org/pod/MooX::File::ConfigDir#config_identifier). 119 120 package Foo; 121 122 # apply role MooX::ConfigFromFile::Role and override default for 123 # attribute config_identifier - means to look e.g. in /etc/foo/ 124 use MooX::ConfigFromFile config_identifier => "foo"; 125 126 ... 127 128- `config_hashmergeloaded` 129 130 Consumes role [MooX::ConfigFromFile::Role::HashMergeLoaded](https://metacpan.org/pod/MooX::ConfigFromFile::Role::HashMergeLoaded) directly after 131 [MooX::ConfigFromFile::Role](https://metacpan.org/pod/MooX::ConfigFromFile::Role) has been consumed. 132 133# AUTHOR 134 135Jens Rehsack, `<rehsack at cpan.org>` 136 137# BUGS 138 139Please report any bugs or feature requests to 140`bug-moox-configfromfile at rt.cpan.org`, or through the web interface at 141[http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooX-ConfigFromFile](http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooX-ConfigFromFile). 142I will be notified, and then you'll automatically be notified of progress 143on your bug as I make changes. 144 145# SUPPORT 146 147You can find documentation for this module with the perldoc command. 148 149 perldoc MooX::ConfigFromFile 150 151You can also look for information at: 152 153- RT: CPAN's request tracker (report bugs here) 154 155 [http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooX-ConfigFromFile](http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooX-ConfigFromFile) 156 157- AnnoCPAN: Annotated CPAN documentation 158 159 [http://annocpan.org/dist/MooX-ConfigFromFile](http://annocpan.org/dist/MooX-ConfigFromFile) 160 161- CPAN Ratings 162 163 [http://cpanratings.perl.org/d/MooX-ConfigFromFile](http://cpanratings.perl.org/d/MooX-ConfigFromFile) 164 165- Search CPAN 166 167 [http://search.cpan.org/dist/MooX-ConfigFromFile/](http://search.cpan.org/dist/MooX-ConfigFromFile/) 168 169# ACKNOWLEDGEMENTS 170 171# LICENSE AND COPYRIGHT 172 173Copyright 2013-2018 Jens Rehsack. 174 175This program is free software; you can redistribute it and/or modify it 176under the terms of either: the GNU General Public License as published 177by the Free Software Foundation; or the Artistic License. 178 179See [http://dev.perl.org/licenses/](http://dev.perl.org/licenses/) for more information. 180