Dist::...gDumper(3pm)

πŸ“¦
version 0.003009 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Dist::...gDumper(3pm) β€” aka Dist::Zilla::Util::ConfigDumper πŸ’–

ok so bestie. sit down. hydrate. we're about to talk about a utility module and honestly? it's lowkey iconic.

This page is Dist::...gDumper(3pm) from the User Contributed Perl Documentation, and the module itself is Dist::Zilla::Util::ConfigDumper β€” a Dist::Zilla plugin configuration extraction utility. yes, that's a mouthful. no, we're not renaming it.


✨ VERSION ✨

version 0.003009


🌸 SYNOPSIS 🌸

...

with 'Dist::Zilla::Role::Plugin';
use Dist::Zilla::Util::ConfigDumper qw( config_dumper );

around dump_config => config_dumper( __PACKAGE__, qw( foo bar baz ) );

like. that's it. that's the whole vibe. πŸ¦‹


πŸŽ€ DESCRIPTION πŸŽ€

okay so this module contains a utility function for use within the "Dist::Zilla" plugin ecosystem, and its whole job is to simplify extraction of plugin settings β€” for plugin authors β€” so that plugins like "Dist::Zilla::Plugin::MetaConfig" can expose those values to consumers. it's giving backstage crew energy. nobody claps for it but the show does not go on without it. πŸ’…

Primarily, it specializes in:

  • Making propagating configuration from the plugins inheritance hierarchy nearly foolproof.
  • Providing simple interfaces to extract values of lists of named methods or accessors
  • Providing a way to intelligently and easily probe the value of lazy attributes without triggering their vivification.

that last one?? not me being obsessed with not vivifying lazy attributes. that's self-care fr fr. 🧚


πŸ”₯ FUNCTIONS πŸ”₯

πŸ’œ "config_dumper"

config_dumper( __PACKAGE__, qw( method list ) );

Returns a function suitable for use with "around dump_config".

my $sub = config_dumper( __PACKAGE__, qw( method list ) );
around dump_config => $sub;

Or

around dump_config => sub {
  my ( $orig, $self, @args ) = @_;
  return config_dumper(__PACKAGE__, qw( method list ))->( $orig, $self, @args );
};

Either way:

my $function = config_dumper( $package_name_for_config, qw( methods to call on $self ));
my $hash = $function->( $function_that_returns_a_hash, $instance_to_call_methods_on, @somethinggoeshere );

=~ All of this approximates:

around dump_config => sub {
  my ( $orig , $self , @args ) = @_;
  my $conf = $self->$orig( @args );
  my $payload = {};

  for my $method ( @methods ) {
    try {
      $payload->{ $method } = $self->$method();
    };
  }
  $config->{+__PACKAGE__} = $payload;
}

Except with some extra "things dun goofed" handling. πŸ’€ yes that's the real phrase. we love a graceful failure moment.

πŸ’œ "dump_plugin"

This function serves the other half of the equation, emulating "dzil"'s own internal behavior for extracting the "plugin" configuration data.

for my $plugin ( @{ $zilla->plugins } ) {
  pp( dump_plugin( $plugin )); # could prove useful somewhere.
}

Its not usually something you need, but its useful in:

  • Tests
  • Crazy Stuff like injecting plugins
  • Crazy Stuff like having "Child" plugins

This serves to be a little more complicated than merely calling "->dump_config", as the structure "dzil" uses is:

{
  class   => ...
  name    => ...
  version => ...
  config  => $dump_config_results_here
}

And of course, there's a bunch of magic stuff with "meta", "can" and "if keys %$configresults"

All that insanity is wrapped in this simple interface. iconic behavior honestly β€” the messy parts stay inside, the cute interface goes outside. 🫢


πŸ‘‘ ADVANCED USE πŸ‘‘

🌈 CALLBACKS

Internally

config_dumper( $pkg, qw( method list ) );

Maps to a bunch of subs, so its more like:

config_dumper( $pkg, sub {
  my ( $instance, $payload ) = @_;
  $payload->{'method'} = $instance->method;
}, sub {
  $_[1]->{'list'} = $_[0]->list;
});

So if you want to use that because its more convenient for some problem, be my guest.

around dump_config => config_dumper( __PACKAGE__, sub {
  $_[1]->{'x'} = 'y'
});

is much less ugly than

around dump_config => sub {
  my ( $orig, $self, @args ) = @_;
  my $conf = $self->$orig(@args);
  $config->{+__PACKAGE__} = { # if you forget the +, things break
     'x' => 'y'
  };
  return $config;
};
⚠️ bestie look at me. # if you forget the +, things break. the comment is RIGHT THERE in the original and it is NOT a joke. do not come crying to me. πŸ’€

🌈 DETAILED CONFIGURATION

There's an additional feature for advanced people:

config_dumper( $pkg, \%config );

πŸ“ "attrs"

config_dumper( $pkg, { attrs => [qw( foo bar baz )] });

This is for cases where you want to deal with "Moose" attributes, but want added safety of NOT loading attributes that have no value yet.

For each item in "attrs", we'll call "Moose" attribute internals to determine if the attribute named has a value, and only then will we fetch it. peek before you touch. consent culture but for lazy attributes. ✨


πŸ’– AUTHOR πŸ’–

Kent Fredric <kentnl@cpan.org>


This software is copyright (c) 2017 by Kent Fredric <kentfredric@gmail.com>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


and that's the whole page bestie!! πŸŽ€ this manual page came to you via perl v5.36.0, dated 2022-11-19, and it's the Dist::...gDumper(3pm) page from Dist::Zilla::Util::ConfigDumper 0.003009 β€” go forth and dump your configs responsibly. mwah. πŸ’…πŸ¦‹

πŸ“¦ where this page comes from