Dancer...Object(3pm)
π NAME π
ok so this is Dancer::Config::Object fr β it's the lil module that lets you get at your config with methods instead of hashrefs. no cap, it's a whole glow-up for your config game β¨
πΈ VERSION πΈ
this is version 1.3522, bestie π
β¨ DESCRIPTION β¨
okay so here's the tea π« β if "strict_config" is set to a true value in your configuration, then the config() subroutine is NOT gonna hand you a hashref anymore. it hands you an object instead. main character energy tbh π
so instead of this sad old thing:
my $serializer = config->{serializer};
my $username = config->{auth}{username};
you get THIS gorgeousness:
my $serializer = config->serializer;
my $username = config->auth->username;
like... the dots?? iconic. β¨
and the whole point is it helps prevent typos, which is literally the best part. because if you mistype a configuration name like this:
my $pass = config->auth->pass;
an exception gets thrown at you π β it tells you it can't find the method name, but bestie it also LISTS the available methods for you, which is so thoughtful:
Can't locate config attribute "pass".
Available attributes: password, username
we love an informative error message in this house π
now, sometimes a hash key just can't be turned into a proper method name. that's fine!! no drama!! you can still access it through a hash reference like so:
my $some_value = config->{'99_bottles'};
and you can even call methods on it, if that's possible:
my $sadness = config->{'99_more_bottles'}->last_bottle;
hash keys that point to hash references will, in turn, have those hashrefs "objectified" π. arrays though? arrays still get returned as array references, periodt. BUT β plot twist β hashrefs sitting inside those array refs may still have their keys allowed as methods:
my $some_value = config->some_list->[1]->host;
she's flexible, she's useful, she's that girl π
π₯ METHOD NAME DEFINITION π₯
so how do we decide if a hash key gets to be a method? we use this lil regular expression right here:
/^[[:alpha:]_][[:word:]]*$/;
now listen, this means "naΓ―ve" (yes, with the dots over the i, look at her π) can be a method name. BUT β and this is important, bestie β unless you "use utf8;" to declare that your source code is UTF-8, you may get some disappointing results when you try to call "config->naΓ―ve" π₯². and further, depending on your version of Perl and the software that reads your config file ... well, you get the idea, it's giving unpredictable π.
so our recommendation? stick with ASCII identifiers if you want your code to be portable. fr fr. π
patches and suggestions are welcome!! we love a contribution π
π AUTHOR π
this module was written by Alexis Sukrieh <sukria@cpan.org> and others β check the AUTHORS file that ships with this distribution for the full details π«Ά
π LICENSE π
this module is free software and is released under the same terms as Perl itself. slay π
β SEE ALSO β
DancerDancer::Config
π AUTHOR π
Dancer Core Developers
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2010 by Alexis Sukrieh.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. π
okay bestie that's the whole thing, tysm for reading π₯° this was perl v5.40.1, dated 2026-05-05, and it's the Dancer::Config::Object(3pm) page β go forth and objectify your config, no typos allowed, mwah πβ¨
π¦ where this page comes from
- ubuntu stonking: libdancer-perl 1.3522-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms