1MooX::ConfigFromFile(3)User Contributed Perl DocumentatioMnooX::ConfigFromFile(3)
2
3
4

NAME

6       MooX::ConfigFromFile - Moo eXtension for initializing objects from
7       config file
8

SYNOPSIS

10          package Role::Action;
11
12          use Moo::Role;
13
14          has operator => ( is => "ro" );
15
16          package Action;
17
18          use Moo;
19          use MooX::ConfigFromFile; # imports the MooX::ConfigFromFile::Role
20
21          with "Role::Action";
22
23          sub operate { return say shift->operator; }
24
25          package OtherAction;
26
27          use Moo;
28
29          with "Role::Action", "MooX::ConfigFromFile::Role";
30
31          sub operate { return warn shift->operator; }
32
33          package QuiteOtherOne;
34
35          use Moo;
36
37          # consumes the MooX::ConfigFromFile::Role but load config only once
38          use MooX::ConfigFromFile config_singleton => 1;
39
40          with "Role::Action";
41
42          sub _build_config_prefix { "die" }
43
44          sub operate { return die shift->operator; }
45
46          package main;
47
48          my $action = Action->new(); # tries to find a config file in config_dirs and loads it
49          my $other = OtherAction->new( config_prefix => "warn" ); # use another config file
50          my $quite_o = QuiteOtherOne->new(); # quite another way to have an individual config file
51

DESCRIPTION

53       This module is intended to easy load initialization values for
54       attributes on object construction from an appropriate config file. The
55       building is done in MooX::ConfigFromFile::Role - using
56       MooX::ConfigFromFile ensures the role is applied.
57
58       For easier usage, with 0.004, several options can be passed via use
59       resulting in default initializers for appropriate role attributes:
60
61       "config_prefix"
62           Default for "config_prefix" in MooX::ConfigFromFile::Role.
63
64       "config_prefixes"
65           Default for "config_prefixes" in MooX::ConfigFromFile::Role. Ensure
66           when use this flag together with MooX::Cmd to load
67           "MooX::ConfigFromFile" before "MooX::Cmd".
68
69       "config_prefix_map_separator"
70           Default for "config_prefix_map_separator" in
71           MooX::ConfigFromFile::Role.
72
73             package Foo;
74
75             # apply role MooX::ConfigFromFile::Role and override default for
76             # attribute config_prefix_map_separator
77             use MooX::ConfigFromFile config_prefix_map_separator => "~";
78
79             ...
80
81       "config_extensions"
82           Default for "config_extensions" in MooX::ConfigFromFile::Role.
83
84       "config_dirs"
85           Default for "config_dirs" in MooX::ConfigFromFile::Role.  Same
86           warning regarding modifying this attribute applies here: Possible,
87           but use with caution!
88
89             package Foo;
90
91             use MooX::ConfigFromFile config_dirs => [qw(/opt/foo/etc /home/alfred/area/foo/etc)];
92
93             ...
94
95       "config_files"
96           Default for "config_files" in MooX::ConfigFromFile::Role.
97
98           Reasonable when you want exactly one config file in development
99           mode.  For production code it is highly recommended to override the
100           builder.
101
102       "config_singleton"
103           Flag adding a wrapper around the builder of "loaded_config" in
104           MooX::ConfigFromFile::Role to ensure a config is loaded only once
105           per class. The per class restriction results from applicable
106           modifiers per class (and singletons are per class).
107
108       "config_identifier"
109           Default for "config_identifier" in MooX::File::ConfigDir.
110
111             package Foo;
112
113             # apply role MooX::ConfigFromFile::Role and override default for
114             # attribute config_identifier - means to look e.g. in /etc/foo/
115             use MooX::ConfigFromFile config_identifier => "foo";
116
117             ...
118
119       "config_hashmergeloaded"
120           Consumes role MooX::ConfigFromFile::Role::HashMergeLoaded directly
121           after MooX::ConfigFromFile::Role has been consumed.
122

AUTHOR

124       Jens Rehsack, "<rehsack at cpan.org>"
125

BUGS

127       Please report any bugs or feature requests to "bug-moox-configfromfile
128       at rt.cpan.org", or through the web interface at
129       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooX-ConfigFromFile>.
130       I will be notified, and then you'll automatically be notified of
131       progress on your bug as I make changes.
132

SUPPORT

134       You can find documentation for this module with the perldoc command.
135
136           perldoc MooX::ConfigFromFile
137
138       You can also look for information at:
139
140       •   RT: CPAN's request tracker (report bugs here)
141
142           <http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooX-ConfigFromFile>
143
144       •   AnnoCPAN: Annotated CPAN documentation
145
146           <http://annocpan.org/dist/MooX-ConfigFromFile>
147
148       •   CPAN Ratings
149
150           <http://cpanratings.perl.org/d/MooX-ConfigFromFile>
151
152       •   Search CPAN
153
154           <http://search.cpan.org/dist/MooX-ConfigFromFile/>
155

ACKNOWLEDGEMENTS

158       Copyright 2013-2018 Jens Rehsack.
159
160       This program is free software; you can redistribute it and/or modify it
161       under the terms of either: the GNU General Public License as published
162       by the Free Software Foundation; or the Artistic License.
163
164       See <http://dev.perl.org/licenses/> for more information.
165
166
167
168perl v5.36.0                      2022-07-22           MooX::ConfigFromFile(3)
Impressum