1MooseX::SimpleConfig(3pUms)er Contributed Perl DocumentatMiooonseX::SimpleConfig(3pm)
2
3
4

NAME

6       MooseX::SimpleConfig - A Moose role for setting attributes from a
7       simple configuration file
8

VERSION

10       version 0.11
11

SYNOPSIS

13         ## A YAML configfile named /etc/my_app.yaml:
14         foo: bar
15         baz: 123
16
17         ## In your class
18         package My::App;
19         use Moose;
20
21         with 'MooseX::SimpleConfig';
22
23         has 'foo' => (is => 'ro', isa => 'Str', required => 1);
24         has 'baz'  => (is => 'rw', isa => 'Int', required => 1);
25
26         # ... rest of the class here
27
28         ## in your script
29         #!/usr/bin/perl
30
31         use My::App;
32
33         my $app = My::App->new_with_config(configfile => '/etc/my_app.yaml');
34         # ... rest of the script here
35
36         ####################
37         ###### combined with MooseX::Getopt:
38
39         ## In your class
40         package My::App;
41         use Moose;
42
43         with 'MooseX::SimpleConfig';
44         with 'MooseX::Getopt';
45
46         has 'foo' => (is => 'ro', isa => 'Str', required => 1);
47         has 'baz'  => (is => 'rw', isa => 'Int', required => 1);
48
49         # ... rest of the class here
50
51         ## in your script
52         #!/usr/bin/perl
53
54         use My::App;
55
56         my $app = My::App->new_with_options();
57         # ... rest of the script here
58
59         ## on the command line
60         % perl my_app_script.pl -configfile /etc/my_app.yaml -otherthing 123
61

DESCRIPTION

63       This role loads simple files to set object attributes.  It is based on
64       the abstract role MooseX::ConfigFromFile, and uses Config::Any to load
65       your configuration file.  Config::Any will in turn support any of a
66       variety of different config formats, detected by the file extension.
67       See Config::Any for more details about supported formats.
68
69       To pass additional arguments to Config::Any you must provide a
70       "config_any_args()" method, for example:
71
72         sub config_any_args {
73           return {
74             driver_args => { General => { '-InterPolateVars' => 1 } }
75           };
76         }
77
78       Like all MooseX::ConfigFromFile -derived file loaders, this module is
79       automatically supported by the MooseX::Getopt role as well, which
80       allows specifying "-configfile" on the command line.
81

ATTRIBUTES

83   configfile
84       Provided by the base role MooseX::ConfigFromFile.  You can provide a
85       default configuration file pathname like so:
86
87         has '+configfile' => ( default => '/etc/myapp.yaml' );
88
89       You can pass an array of filenames if you want, but as usual the array
90       has to be wrapped in a sub ref.
91
92         has '+configfile' => ( default => sub { [ '/etc/myapp.yaml', '/etc/myapp_local.yml' ] } );
93
94       Config files are trivially merged at the top level, with the right-hand
95       files taking precedence.
96

CLASS METHODS

98   new_with_config
99       Provided by the base role MooseX::ConfigFromFile.  Acts just like
100       regular "new()", but also accepts an argument "configfile" to specify
101       the file from which to load other attributes.  Explicit arguments to
102       "new_with_config" will override anything loaded from the file.
103
104   get_config_from_file
105       Called internally by either "new_with_config" or MooseX::Getopt's
106       "new_with_options".  Invokes Config::Any to parse "configfile".
107

AUTHOR

109       Brandon L. Black <blblack@gmail.com>
110
112       This software is copyright (c) 2007 by Brandon L. Black
113       <blblack@gmail.com>.
114
115       This is free software; you can redistribute it and/or modify it under
116       the same terms as the Perl 5 programming language system itself.
117

CONTRIBUTORS

119       ·   Karen Etheridge <ether@cpan.org>
120
121       ·   Tomas Doran <bobtfish@bobtfish.net>
122
123       ·   Brandon L Black <blblack@gmail.com>
124
125       ·   Alexander Hartmaier <alex.hartmaier@gmail.com>
126
127       ·   lestrrat <lestrrat+github@gmail.com>
128
129       ·   XXXXXX XXXXXXX <sromanov@cpan.org>
130
131       ·   Yuval Kogman <nothingmuch@woobling.org>
132
133       ·   Zbigniew Lukasiak <zby@cpan.org>
134
135       ·   Alex Howarth <alex.howarth@gmail.com>
136
137
138
139perl v5.28.0                      2014-11-16         MooseX::SimpleConfig(3pm)
Impressum