1Dancer::Config::Object(U3s)er Contributed Perl DocumentatDiaonncer::Config::Object(3)
2
3
4
6 Dancer::Config::Object - Access the config via methods instead of
7 hashrefs
8
10 version 1.3512
11
13 If "strict_config" is set to a true value in the configuration, the
14 "config()" subroutine will return an object instead of a hashref.
15 Instead of this:
16
17 my $serializer = config->{serializer};
18 my $username = config->{auth}{username};
19
20 You get this:
21
22 my $serializer = config->serializer;
23 my $username = config->auth->username;
24
25 This helps to prevent typos. If you mistype a configuration name:
26
27 my $pass = config->auth->pass;
28
29 An exception will be thrown, tell you it can't find the method name,
30 but listing available methods:
31
32 Can't locate config attribute "pass".
33 Available attributes: password, username
34
35 If the hash key cannot be converted into a proper method name, you can
36 still access it via a hash reference:
37
38 my $some_value = config->{'99_bottles'};
39
40 And call methods on it, if possible:
41
42 my $sadness = config->{'99_more_bottles'}->last_bottle;
43
44 Hash keys pointing to hash references will in turn have those
45 "objectified". Arrays will still be returned as array references.
46 However, hashrefs inside of the array refs may still have their keys
47 allowed as methods:
48
49 my $some_value = config->some_list->[1]->host;
50
52 We use the following regular expression to determine if a hash key
53 qualifies as a method:
54
55 /^[[:alpha:]_][[:word:]]*$/;
56
57 Note that this means "naïve" (note the dots over the i) can be a method
58 name, but unless you "use utf8;" to declare that your source code is
59 UTF-8, you may have disappointing results calling "config->naïve".
60 Further, depending on your version of Perl and the software to read
61 your config file ... well, you get the idea. We recommend sticking with
62 ASCII identifiers if you wish your code to be portable.
63
64 Patches/suggestions welcome.
65
67 This module has been written by Alexis Sukrieh <sukria@cpan.org> and
68 others, see the AUTHORS file that comes with this distribution for
69 details.
70
72 This module is free software and is released under the same terms as
73 Perl itself.
74
76 Dancer and Dancer::Config.
77
79 Dancer Core Developers
80
82 This software is copyright (c) 2010 by Alexis Sukrieh.
83
84 This is free software; you can redistribute it and/or modify it under
85 the same terms as the Perl 5 programming language system itself.
86
87
88
89perl v5.28.1 2019-03-31 Dancer::Config::Object(3)