README
[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.
69
70 CLASS METHODS
71   new_with_config
72     Provided by the base role MooseX::ConfigFromFile. Acts just like regular
73     "new()", but also accepts an argument "configfile" to specify the
74     configfile from which to load other attributes. Explicit arguments to
75     "new_with_config" will override anything loaded from the configfile.
76
77   get_config_from_file
78     Called internally by either "new_with_config" or MooseX::Getopt's
79     "new_with_options". Invokes Config::Any to parse "configfile".
80
81 AUTHOR
82     Brandon L. Black, <blblack@gmail.com>
83
84 LICENSE
85     This library is free software; you can redistribute it and/or modify it
86     under the same terms as Perl itself.
87