Can I install dist-zilla in arbitrary fields in a template file?

Is there a way to have a custom parameter in the file and then dist.ini set the value for the parameter. For example, a file might contain {{$THE_ANSWER}} , and a dist.ini file should contain a value like THE_ANSWER = 42 ? I'm new to using dist::zilla to work with perl distributions, and I'm having trouble understanding how it treats files as templates. It seems that there are only a couple of hard-coded parameters that vary by the plugin, which can be used for any file. One such parameter is the {{$ NEXT}} variable, available on [NextRelease] in the Changes file.

I read the tutorials and searched for modules on CPAN and cannot figure out if this is possible. It is not possible to use the [GenerateFile] plugin to put the entire file in the dist.ini file. Besides the lack of flexibility and simple ugliness, it is not possible to add lines with leading white space in this way.

+4
source share
1 answer

What I would do is use a stash or plugin to store variables. Bookmarks are like plugins, but they do nothing but store data, and you can put them in your global configuration, as well as in your dist.ini .

 [%Vars] favorite_pie = pumpkin 

Then you can get them like this:

 $zilla->stash_named('%Vars')->favorite_pie 

This assumes that you made Dist :: Zilla :: Stash :: Vars and assigned it the favorite_pie attribute.

You could make a completely general circulation, though, which takes something as a key. To do this, I would look at the source Dist :: Zilla :: Plugin :: Prereqs, which allows arbitrary configuration parameters and drags them into a hash attribute in my BUILDSARGS method.

You can do this Dist :: Zilla :: Stash :: Generic and then register it as many times as you want for various reasons:

 [%Generic / Pies] favorite = pumpkin hated = rhubarb firstever = quince [%Generic / Passwords] pause = PeasAreDelicious google = secret reddit = SecretPeasAreDelicious 

... then, if necessary, let's say in the templates ...

 {{ $zilla->stash_named('Passwords')->get_var('pause' }} 

If I were to make a lot of files that used this generic thing, I would pass them a Text :: Template closure instance called get_password as follows:

 get_password => sub { $zilla->stash_named('Passwords')->get_var($_[0]) } 

Your template may then include:

 Login with: {{ get_password("pause") }} 

This answer obviously leaves you with some kind of source digger, but I think it should point out all the parts that I will use to do what you want.

+5
source

Source: https://habr.com/ru/post/1433260/


All Articles