Merge branch 'master' of git.moose.perl.org:MooseX-SimpleConfig
[gitmo/MooseX-SimpleConfig.git] / README
1 NAME
2     MooseX::SimpleConfig - A Moose role for setting attributes from a simple
3     configfile
4
5 SYNOPSIS
6       ## A YAML configfile named /etc/my_app.yaml:
7       foo: bar
8       baz: 123
9
10       ## In your class
11       package My::App;
12       use Moose;
13
14       with 'MooseX::SimpleConfig';
15
16       has 'foo' => (is => 'ro', isa => 'Str', required => 1);
17       has 'baz'  => (is => 'rw', isa => 'Int', required => 1);
18
19       # ... rest of the class here
20
21       ## in your script
22       #!/usr/bin/perl
23
24       use My::App;
25
26       my $app = My::App->new_with_config(configfile => '/etc/my_app.yaml');
27       # ... rest of the script here
28
29       ####################
30       ###### combined with MooseX::Getopt:
31
32       ## In your class
33       package My::App;
34       use Moose;
35
36       with 'MooseX::SimpleConfig';
37       with 'MooseX::Getopt';
38
39       has 'foo' => (is => 'ro', isa => 'Str', required => 1);
40       has 'baz'  => (is => 'rw', isa => 'Int', required => 1);
41
42       # ... rest of the class here
43
44       ## in your script
45       #!/usr/bin/perl
46
47       use My::App;
48
49       my $app = My::App->new_with_options();
50       # ... rest of the script here
51
52       ## on the command line
53       % perl my_app_script.pl -configfile /etc/my_app.yaml -otherthing 123
54
55 DESCRIPTION
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.
61
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.
65
66 ATTRIBUTES
67   configfile
68     Provided by the base role MooseX::ConfigFromFile. You can provide a
69     default configfile pathname like so:
70
71       has +configfile ( default => '/etc/myapp.yaml' );
72
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.
75
76       has +configfile ( default => sub { [ '/etc/myapp.yaml', '/etc/myapp_local.yml' ] } );
77
78     Config files are trivially merged at the top level, with the right-hand
79     files taking precedence.
80
81 CLASS METHODS
82   new_with_config
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.
87
88   get_config_from_file
89     Called internally by either "new_with_config" or MooseX::Getopt's
90     "new_with_options". Invokes Config::Any to parse "configfile".
91
92 AUTHOR
93     Brandon L. Black, <blblack@gmail.com>
94
95 LICENSE
96     This library is free software; you can redistribute it and/or modify it
97     under the same terms as Perl itself.
98