1MooseX::SimpleConfig(3)User Contributed Perl DocumentatioMnooseX::SimpleConfig(3)
2
3
4

NAME

6       MooseX::SimpleConfig - A Moose role for setting attributes from a
7       simple configfile
8

SYNOPSIS

10         ## A YAML configfile named /etc/my_app.yaml:
11         foo: bar
12         baz: 123
13
14         ## In your class
15         package My::App;
16         use Moose;
17
18         with 'MooseX::SimpleConfig';
19
20         has 'foo' => (is => 'ro', isa => 'Str', required => 1);
21         has 'baz'  => (is => 'rw', isa => 'Int', required => 1);
22
23         # ... rest of the class here
24
25         ## in your script
26         #!/usr/bin/perl
27
28         use My::App;
29
30         my $app = My::App->new_with_config(configfile => '/etc/my_app.yaml');
31         # ... rest of the script here
32
33         ####################
34         ###### combined with MooseX::Getopt:
35
36         ## In your class
37         package My::App;
38         use Moose;
39
40         with 'MooseX::SimpleConfig';
41         with 'MooseX::Getopt';
42
43         has 'foo' => (is => 'ro', isa => 'Str', required => 1);
44         has 'baz'  => (is => 'rw', isa => 'Int', required => 1);
45
46         # ... rest of the class here
47
48         ## in your script
49         #!/usr/bin/perl
50
51         use My::App;
52
53         my $app = My::App->new_with_options();
54         # ... rest of the script here
55
56         ## on the command line
57         % perl my_app_script.pl -configfile /etc/my_app.yaml -otherthing 123
58

DESCRIPTION

60       This role loads simple configfiles to set object attributes.  It is
61       based on the abstract role MooseX::ConfigFromFile, and uses Config::Any
62       to load your configfile.  Config::Any will in turn support any of a
63       variety of different config formats, detected by the file extension.
64       See Config::Any for more details about supported formats.
65
66       Like all MooseX::ConfigFromFile -derived configfile loaders, this
67       module is automatically supported by the MooseX::Getopt role as well,
68       which allows specifying "-configfile" on the commandline.
69

ATTRIBUTES

71   configfile
72       Provided by the base role MooseX::ConfigFromFile.  You can provide a
73       default configfile pathname like so:
74
75         has +configfile ( default => '/etc/myapp.yaml' );
76

CLASS METHODS

78   new_with_config
79       Provided by the base role MooseX::ConfigFromFile.  Acts just like
80       regular "new()", but also accepts an argument "configfile" to specify
81       the configfile from which to load other attributes.  Explicit arguments
82       to "new_with_config" will override anything loaded from the configfile.
83
84   get_config_from_file
85       Called internally by either "new_with_config" or MooseX::Getopt's
86       "new_with_options".  Invokes Config::Any to parse "configfile".
87

AUTHOR

89       Brandon L. Black, <blblack@gmail.com>
90

LICENSE

92       This library is free software; you can redistribute it and/or modify it
93       under the same terms as Perl itself.
94
95
96
97perl v5.12.0                      2008-01-23           MooseX::SimpleConfig(3)
Impressum