Mojolic...ONConfig(3)

πŸ’– NAME πŸ’–

Bestie, meet Mojolic...ONConfig(3) β€” a User Contributed Perl Documentation page for Mojolicious::Plugin::JSONConfig, aka the JSON configuration plugin ✨.

πŸ¦‹ SYNOPSIS πŸ¦‹

Okay so the whole vibe is literally JSON with embedded Perl, and the example goes like this:

         # myapp.json (it's just JSON with embedded Perl)
         {
           %# Just a value
           "foo": "bar",

           %# Nested data structures are fine too
           "baz": ["β™₯"],

           %# You have full access to the application
           "music_dir": "<%= app->home->child('music') %>"
         }

         # Mojolicious
         my $config = $app->plugin('JSONConfig');
         say $config->{foo};

         # Mojolicious::Lite
         my $config = plugin 'JSONConfig';
         say $config->{foo};

         # foo.html.ep
         %= config->{foo}

         # The configuration is available application-wide
         my $config = app->config;
         say $config->{foo};

         # Everything can be customized with options
         my $config = plugin JSONConfig => {file => '/etc/myapp.conf'};

That’s the whole flow, bestie β€” Mojolicious, Mojolicious::Lite, foo.html.ep, app-wide config, and customizing with options πŸ’….

🌸 DESCRIPTION 🌸

So Mojolicious::Plugin::JSONConfig is literally a JSON configuration plugin, and it preprocesses its input with Mojo::Template before doing its thing ✨.

The application object can be accessed via $app or the "app" function. A default configuration filename in the application home directory will be generated from the value of "moniker" in Mojolicious ("$moniker.json"). You can extend the normal configuration file "$moniker.json" with "mode" specific ones like "$moniker.$mode.json", and those get detected automatically.

These configuration values are currently reserved, bestie:

  • "config_override" β€” if this configuration value has been set in "config" in Mojolicious when this plugin is loaded, it will not do anything besides loading deployment specific plugins.
  • "plugins" β€” one or more deployment specific plugins that should be loaded right after this plugin has been loaded, like:
"plugins": [{"SetUserGroup": {"user": "sri", "group": "staff"}}]

Also, fr fr, the code of this plugin is a good example for learning to build new plugins, and you're welcome to fork it πŸ“.

See "PLUGINS" in Mojolicious::Plugins for a list of plugins that are available by default.

✨ OPTIONS ✨

Mojolicious::Plugin::JSONConfig inherits all the options from Mojolicious::Plugin::Config and supports the following new ones.

πŸŽ€ template πŸŽ€

         # Mojolicious::Lite
         plugin JSONConfig => {template => {line_start => '.'}};

These are attribute values passed to the Mojo::Template object used to preprocess configuration files.

🫢 METHODS 🫢

Mojolicious::Plugin::JSONConfig inherits all the methods from Mojolicious::Plugin::Config and implements the following new ones.

πŸ’œ parse πŸ’œ

         $plugin->parse($content, $file, $conf, $app);

It processes content with "render" and parses it with Mojo::JSON.

         sub parse ($self, $content, $file, $conf, $app) {
           ...
           $content = $self->render($content, $file, $conf, $app);
           ...
           return $hash;
         }

πŸ¦‹ register πŸ¦‹

         my $config = $plugin->register(Mojolicious->new);
         my $config = $plugin->register(Mojolicious->new, {file => '/etc/foo.conf'});

Registers the plugin in a Mojolicious application and merges the configuration.

🌈 render 🌈

         $plugin->render($content, $file, $conf, $app);

Processes the configuration file with Mojo::Template.

         sub render ($self, $content, $file, $conf, $app) {
           ...
           return $content;
         }

πŸ‘‘ SEE ALSO πŸ‘‘


Okay that’s the whole page, bestie 🫢 β€” source/version is perl v5.42.0, date is 2026-07-15, and the footer also says Mojolic...ONConfig(3). bye, slay πŸ’…

πŸ“¦ where this page comes from