1MouseX::SimpleConfig(3)User Contributed Perl DocumentatioMnouseX::SimpleConfig(3)
2
3
4
6 MouseX::SimpleConfig - A Mouse role for setting attributes from a
7 simple configfile
8
10 version 0.11
11
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 Mouse;
20
21 with 'MouseX::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 MouseX::Getopt:
38
39 ## In your class
40 package My::App;
41 use Mouse;
42
43 with 'MouseX::SimpleConfig';
44 with 'MouseX::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
63 This role loads simple configfiles to set object attributes. It is
64 based on the abstract role MouseX::ConfigFromFile, and uses Config::Any
65 to load your configfile. 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 Like all MouseX::ConfigFromFile -derived configfile loaders, this
70 module is automatically supported by the MouseX::Getopt role as well,
71 which allows specifying "-configfile" on the commandline.
72
74 configfile
75 Provided by the base role MouseX::ConfigFromFile. You can provide a
76 default configfile pathname like so:
77
78 has '+configfile' => ( default => '/etc/myapp.yaml' );
79
80 You can pass an array of filenames if you want, but as usual the array
81 has to be wrapped in a sub ref.
82
83 has '+configfile' => ( default => sub { [ '/etc/myapp.yaml', '/etc/myapp_local.yml' ] } );
84
85 Config files are trivially merged at the top level, with the right-hand
86 files taking precedence.
87
89 new_with_config
90 Class method provided by the base role MouseX::ConfigFromFile. Acts
91 just like regular "new()", but also accepts an argument "configfile" to
92 specify the configfile from which to load other attributes. Explicit
93 arguments to "new_with_config" will override anything loaded from the
94 configfile.
95
96 get_config_from_file
97 Class method called internally by either "new_with_config" or
98 MouseX::Getopt's "new_with_options". Invokes Config::Any to parse
99 "configfile".
100
102 Please report any bugs or feature requests on the bugtracker website
103 http://github.com/mjg/MouseX-SimpleConfig/issues
104
105 When submitting a bug or request, please include a test-file or a patch
106 to an existing test-file that illustrates the bug or desired feature.
107
109 • Brandon L. Black <blblack@gmail.com>
110
111 • Mark Gardner <mjgardner@cpan.org>
112
114 This software is copyright (c) 2011 by Infinity Interactive.
115
116 This is free software; you can redistribute it and/or modify it under
117 the same terms as the Perl 5 programming language system itself.
118
119
120
121perl v5.32.1 2021-01-27 MouseX::SimpleConfig(3)