MouseX:...eConfig(3)
π NAME π
MouseX::SimpleConfig β a Mouse role that sets your attributes from a simple configfile. That's it, that's the whole vibe. β¨
πΈ VERSION πΈ
version 0.11 β she's on 0.11, bestie, and she's thriving.
π¦ SYNOPSIS π¦
okay so picture this: a YAML configfile living at /etc/my_app.yaml π
## A YAML configfile named /etc/my_app.yaml:
foo: bar
baz: 123
and then your class, doing its thing:
## In your class
package My::App;
use Mouse;
with 'MouseX::SimpleConfig';
has 'foo' => (is => 'ro', isa => 'Str', required => 1);
has 'baz' => (is => 'rw', isa => 'Int', required => 1);
# ... rest of the class here
and then your script, living its truth:
## in your script
#!/usr/bin/perl
use My::App;
my $app = My::App->new_with_config(configfile => '/etc/my_app.yaml');
# ... rest of the script here
π and NOW, the crossover episode: combined with MouseX::Getopt π
class first:
## In your class
package My::App;
use Mouse;
with 'MouseX::SimpleConfig';
with 'MouseX::Getopt';
has 'foo' => (is => 'ro', isa => 'Str', required => 1);
has 'baz' => (is => 'rw', isa => 'Int', required => 1);
# ... rest of the class here
script next:
## in your script
#!/usr/bin/perl
use My::App;
my $app = My::App->new_with_options();
# ... rest of the script here
and then from the command line, because she contains multitudes:
## on the command line
% perl my_app_script.pl -configfile /etc/my_app.yaml -otherthing 123
β¨ DESCRIPTION β¨
So this role loads simple configfiles and uses them to set object attributes. It's built on top of the abstract role MouseX::ConfigFromFile, and it uses Config::Any to actually load your configfile. Config::Any in turn supports any of a variety of different config formats, and it figures out which one you mean by looking at the file extension π β see Config::Any for more details about supported formats.
Like all MouseX::ConfigFromFile -derived configfile loaders, this module is automatically supported by the MouseX::Getopt role as well, which means you get to specify -configfile on the commandline. iconic behavior, truly. π
π ATTRIBUTES π
configfile
Provided by the base role MouseX::ConfigFromFile. You can hand her a default configfile pathname like so:
has '+configfile' => ( default => '/etc/myapp.yaml' );
You can pass an array of filenames if you want β but as usual, the array has to be wrapped in a sub ref. no exceptions, that's the rule, periodt.
has '+configfile' => ( default => sub { [ '/etc/myapp.yaml', '/etc/myapp_local.yml' ] } );
Config files are trivially merged at the top level, with the right-hand files taking precedence. right-hand file wins, that's just how it is π«Ά
π METHODS π
new_with_config
Class method provided by the base role MouseX::ConfigFromFile. Acts just like regular new(), but she also accepts an argument "configfile" to specify the configfile from which to load other attributes. And here's the tea β: explicit arguments to "new_with_config" will override anything loaded from the configfile.
get_config_from_file
Class method called internally by either "new_with_config" or MouseX::Getopt's "new_with_options". It invokes Config::Any to parse "configfile". she's backstage, doing the work, no credit, we love her π
π BUGS π
Please report any bugs or feature requests on the bugtracker website http://github.com/mjg/MouseX-SimpleConfig/issues
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. receipts, bestie β bring receipts. π
π AUTHORS π
- Brandon L. Black <blblack@gmail.com>
- Mark Gardner <mjgardner@cpan.org>
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2011 by Infinity Interactive.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
okay that's the whole page!! π¦ generated with perl v5.42.0 on 2025-07-25 β mwah, go forth and configure πβ¨πΈ
π¦ where this page comes from
- fedora 43: perl-MouseX-SimpleConfig 0.11-38.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms