.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" 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 .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "Config::MethodProxy 3pm" .TH Config::MethodProxy 3pm "2018-08-26" "perl v5.26.2" "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" Config::MethodProxy \- Integrate dynamic logic with static configuration. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Config::MethodProxy; \& \& $config = get_your_config_somewhere(); \& $config = apply_method_proxies( $config ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" A method proxy is a particular data structure which, when found, is replaced by the value returned by calling that method. In this way static configuration can be setup to call your code and return dynamic contents. This makes static configuration much more powerful, and gives you the ability to be more declarative in how dynamic values make it into your configuration. .SH "EXAMPLE" .IX Header "EXAMPLE" Consider this static \s-1YAML\s0 configuration: .PP .Vb 5 \& \-\-\- \& db: \& dsn: DBI:mysql:database=foo \& username: bar \& password: abc123 .Ve .PP Putting your database password inside of a configuration file is usually considered a bad practice. You can use a method proxy to get around this without jumping through a bunch of hoops: .PP .Vb 9 \& \-\-\- \& db: \& dsn: DBI:mysql:database=foo \& username: bar \& password: \& \- $proxy \& \- MyApp::Config \& \- get_db_password \& \- bar .Ve .PP When \*(L"apply_method_proxies\*(R" is called on the above data structure it will see the method proxy and will replace the array ref with the return value of calling the method. .PP A method proxy, in Perl syntax, looks like this: .PP .Vb 1 \& [\*(Aq$proxy\*(Aq, $package, $method, @args] .Ve .PP The \f(CW$proxy\fR string can also be written as \f(CW&proxy\fR. The above is then converted to a method call and replaced by the return value of the method call: .PP .Vb 1 \& $package\->$method( @args ); .Ve .PP In the above database password example the method call would be this: .PP .Vb 1 \& MyApp::Config\->get_db_password( \*(Aqbar\*(Aq ); .Ve .PP You would still need to create a \f(CW\*(C`MyApp::Config\*(C'\fR package, and add a \&\f(CW\*(C`get_db_password\*(C'\fR method to it. .SH "FUNCTIONS" .IX Header "FUNCTIONS" Only the \*(L"apply_method_proxies\*(R" function is exported by default. .SS "apply_method_proxies" .IX Subsection "apply_method_proxies" .Vb 1 \& $config = apply_method_proxies( $config ); .Ve .PP Traverses the supplied data looking for method proxies, calling them, and replacing them with the return value of the method. Any value may be passed, such as a hash ref, an array ref, a method proxy, an object, a scalar, etc. Array and hash refs will be recursively searched for method proxies. .PP If a circular reference is detected an error will be thrown. .SS "is_method_proxy" .IX Subsection "is_method_proxy" .Vb 1 \& if (is_method_proxy( $some_data )) { ... } .Ve .PP Returns true if the supplied data is an array ref where the first value is the string \f(CW$proxy\fR or \f(CW&proxy\fR. .SS "call_method_proxy" .IX Subsection "call_method_proxy" .Vb 1 \& call_method_proxy( [\*(Aq$proxy\*(Aq, $package, $method, @args] ); .Ve .PP Calls a method proxy and returns the value. .SH "AUTHOR" .IX Header "AUTHOR" Aran Clary Deltac .SH "ACKNOWLEDGEMENTS" .IX Header "ACKNOWLEDGEMENTS" Thanks to ZipRecruiter for encouraging their employees to contribute back to the open source ecosystem. Without their dedication to quality software development this distribution would not exist. .SH "LICENSE" .IX Header "LICENSE" This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.