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 ⭐

  • Dancer
  • Dancer::Config

πŸ‘‘ AUTHOR πŸ‘‘

Dancer Core Developers


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