.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Dist::Zilla::Util::ConfigDumper 3pm" .TH Dist::Zilla::Util::ConfigDumper 3pm "2021-01-07" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Dist::Zilla::Util::ConfigDumper \- A Dist::Zilla plugin configuration extraction utility .SH "VERSION" .IX Header "VERSION" version 0.003009 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& ... \& \& with \*(AqDist::Zilla::Role::Plugin\*(Aq; \& use Dist::Zilla::Util::ConfigDumper qw( config_dumper ); \& \& around dump_config => config_dumper( _\|_PACKAGE_\|_, qw( foo bar baz ) ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module contains a utility function for use within the \f(CW\*(C`Dist::Zilla\*(C'\fR plugin ecosystem, to simplify extraction of plugin settings for plugin authors, in order for plugins like \f(CW\*(C`Dist::Zilla::Plugin::MetaConfig\*(C'\fR to expose those values to consumers. .PP Primarily, it specializes in: .IP "\(bu" 4 Making propagating configuration from the plugins inheritance hierarchy nearly foolproof. .IP "\(bu" 4 Providing simple interfaces to extract values of lists of named methods or accessors .IP "\(bu" 4 Providing a way to intelligently and easily probe the value of lazy attributes without triggering their vivification. .SH "FUNCTIONS" .IX Header "FUNCTIONS" .ie n .SS """config_dumper""" .el .SS "\f(CWconfig_dumper\fP" .IX Subsection "config_dumper" .Vb 1 \& config_dumper( _\|_PACKAGE_\|_, qw( method list ) ); .Ve .PP Returns a function suitable for use with \f(CW\*(C`around dump_config\*(C'\fR. .PP .Vb 2 \& my $sub = config_dumper( _\|_PACKAGE_\|_, qw( method list ) ); \& around dump_config => $sub; .Ve .PP Or .PP .Vb 4 \& around dump_config => sub { \& my ( $orig, $self, @args ) = @_; \& return config_dumper(_\|_PACKAGE_\|_, qw( method list ))\->( $orig, $self, @args ); \& }; .Ve .PP Either way: .PP .Vb 2 \& 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 ); .Ve .PP =~ All of this approximates: .PP .Vb 4 \& 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; \& } .Ve .PP Except with some extra \*(L"things dun goofed\*(R" handling. .ie n .SS """dump_plugin""" .el .SS "\f(CWdump_plugin\fP" .IX Subsection "dump_plugin" This function serves the other half of the equation, emulating \f(CW\*(C`dzil\*(C'\fR's own internal behavior for extracting the \f(CW\*(C`plugin\*(C'\fR configuration data. .PP .Vb 3 \& for my $plugin ( @{ $zilla\->plugins } ) { \& pp( dump_plugin( $plugin )); # could prove useful somewhere. \& } .Ve .PP Its not usually something you need, but its useful in: .IP "\(bu" 4 Tests .IP "\(bu" 4 Crazy Stuff like injecting plugins .IP "\(bu" 4 Crazy Stuff like having \*(L"Child\*(R" plugins .PP This serves to be a little more complicated than merely calling \f(CW\*(C`\->dump_config\*(C'\fR, as the structure \f(CW\*(C`dzil\*(C'\fR uses is: .PP .Vb 6 \& { \& class => ... \& name => ... \& version => ... \& config => $dump_config_results_here \& } .Ve .PP And of course, there's a bunch of magic stuff with \f(CW\*(C`meta\*(C'\fR, \f(CW\*(C`can\*(C'\fR and \f(CW\*(C`if keys %$configresults\*(C'\fR .PP All that insanity is wrapped in this simple interface. .SH "ADVANCED USE" .IX Header "ADVANCED USE" .SS "\s-1CALLBACKS\s0" .IX Subsection "CALLBACKS" Internally .PP .Vb 1 \& config_dumper( $pkg, qw( method list ) ); .Ve .PP Maps to a bunch of subs, so its more like: .PP .Vb 6 \& config_dumper( $pkg, sub { \& my ( $instance, $payload ) = @_; \& $payload\->{\*(Aqmethod\*(Aq} = $instance\->method; \& }, sub { \& $_[1]\->{\*(Aqlist\*(Aq} = $_[0]\->list; \& }); .Ve .PP So if you want to use that because its more convenient for some problem, be my guest. .PP .Vb 3 \& around dump_config => config_dumper( _\|_PACKAGE_\|_, sub { \& $_[1]\->{\*(Aqx\*(Aq} = \*(Aqy\*(Aq \& }); .Ve .PP is much less ugly than .PP .Vb 8 \& around dump_config => sub { \& my ( $orig, $self, @args ) = @_; \& my $conf = $self\->$orig(@args); \& $config\->{+_\|_PACKAGE_\|_} = { # if you forget the +, things break \& \*(Aqx\*(Aq => \*(Aqy\*(Aq \& }; \& return $config; \& }; .Ve .SS "\s-1DETAILED CONFIGURATION\s0" .IX Subsection "DETAILED CONFIGURATION" There's an additional feature for advanced people: .PP .Vb 1 \& config_dumper( $pkg, \e%config ); .Ve .PP \fI\f(CI\*(C`attrs\*(C'\fI\fR .IX Subsection "attrs" .PP .Vb 1 \& config_dumper( $pkg, { attrs => [qw( foo bar baz )] }); .Ve .PP This is for cases where you want to deal with \f(CW\*(C`Moose\*(C'\fR attributes, but want added safety of \fB\s-1NOT\s0\fR loading attributes that have no value yet. .PP For each item in \f(CW\*(C`attrs\*(C'\fR, we'll call \f(CW\*(C`Moose\*(C'\fR attribute internals to determine if the attribute named has a value, and only then will we fetch it. .SH "AUTHOR" .IX Header "AUTHOR" Kent Fredric .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2017 by Kent Fredric . .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.