Trim trailing whitespace
[gitmo/MooseX-SimpleConfig.git] / README
CommitLineData
98f0550c 1NAME
2 MooseX::SimpleConfig - A Moose role for setting attributes from a simple
3 configfile
4
5SYNOPSIS
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
55DESCRIPTION
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
66ATTRIBUTES
67 configfile
a96520dd 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' );
98f0550c 72
73CLASS METHODS
74 new_with_config
75 Provided by the base role MooseX::ConfigFromFile. Acts just like regular
76 "new()", but also accepts an argument "configfile" to specify the
77 configfile from which to load other attributes. Explicit arguments to
78 "new_with_config" will override anything loaded from the configfile.
79
80 get_config_from_file
81 Called internally by either "new_with_config" or MooseX::Getopt's
82 "new_with_options". Invokes Config::Any to parse "configfile".
83
84AUTHOR
85 Brandon L. Black, <blblack@gmail.com>
86
87LICENSE
88 This library is free software; you can redistribute it and/or modify it
89 under the same terms as Perl itself.
90