2 MooseX::SimpleConfig - A Moose role for setting attributes from a simple
6 ## A YAML configfile named /etc/my_app.yaml:
14 with 'MooseX::SimpleConfig';
16 has 'foo' => (is => 'ro', isa => 'Str', required => 1);
17 has 'baz' => (is => 'rw', isa => 'Int', required => 1);
19 # ... rest of the class here
26 my $app = My::App->new_with_config(configfile => '/etc/my_app.yaml');
27 # ... rest of the script here
30 ###### combined with MooseX::Getopt:
36 with 'MooseX::SimpleConfig';
37 with 'MooseX::Getopt';
39 has 'foo' => (is => 'ro', isa => 'Str', required => 1);
40 has 'baz' => (is => 'rw', isa => 'Int', required => 1);
42 # ... rest of the class here
49 my $app = My::App->new_with_options();
50 # ... rest of the script here
52 ## on the command line
53 % perl my_app_script.pl -configfile /etc/my_app.yaml -otherthing 123
56 This role loads simple configfiles to set object attributes. It is based
57 on the abstract role MooseX::ConfigFromFile, and uses Config::Any to
58 load your configfile. Config::Any will in turn support any of a variety
59 of different config formats, detected by the file extension. See
60 Config::Any for more details about supported formats.
62 Like all MooseX::ConfigFromFile -derived configfile loaders, this module
63 is automatically supported by the MooseX::Getopt role as well, which
64 allows specifying "-configfile" on the commandline.
68 Provided by the base role MooseX::ConfigFromFile. You can provide a
69 default configfile pathname like so:
71 has '+configfile' => ( default => '/etc/myapp.yaml' );
73 You can pass an array of filenames if you want, but as usual the array
74 has to be wrapped in a sub ref.
76 has '+configfile' => ( default => sub { [ '/etc/myapp.yaml', '/etc/myapp_local.yml' ] } );
78 Config files are trivially merged at the top level, with the right-hand
79 files taking precedence.
83 Provided by the base role MooseX::ConfigFromFile. Acts just like regular
84 "new()", but also accepts an argument "configfile" to specify the
85 configfile from which to load other attributes. Explicit arguments to
86 "new_with_config" will override anything loaded from the configfile.
89 Called internally by either "new_with_config" or MooseX::Getopt's
90 "new_with_options". Invokes Config::Any to parse "configfile".
93 Brandon L. Black, <blblack@gmail.com>
96 This library is free software; you can redistribute it and/or modify it
97 under the same terms as Perl itself.