Dist::Zilla Set B Scene 169 Take 2A
Today in the Dist-Pen I am going to try and get all my version numbers in a row.
Doing some more investigation on how Dist::Zilla will solve another of my distro pains and that is Versioning of my package. I did learn a lesson on version some years again when I though I was doing someone a favor I did a quickie release of DBD::Oracle where the release tar ball didn't match up with the release name.
Go a whole bunch of heat over that breaking a few things that other people where doing. I guess going from 1.23 to 1.24a can really spoil some peoples day, who new? So since that time I have always been very weary about visioning my code.
There is a nice little plugin for Dist::Zilla called 'AutoVersion' which is suppose to fix this sort of thing for you. Up till now I just had
version = 0.01
in my '.ini' and that would change both the name of my tar and the versions in the Build.PL and Makfiel.PL. Now to get AutoVersion to work I first have to get rid of the version line and add in the plugin line;
name = Database-Accessor
--version = 0.01
author = John Scoles
license = GPL_3
copyright_holder = John Scoles
main_module = lib/Database/Accessor.pm
ABSTRACT= test
[GatherDir]
[MakeMaker]
[ModuleBuild]
[AutoPrereqs]
[License]
++[AutoVersion]
and when I build my distro I will see that I get a version # that starts at 1 (the default) and then has a date time component which is suppose to by two digit year with the day count or 'yyDDD' for short. So the default result was;
Database-Accessor-1.180500
which is correct at 50 days (including today) but I am not sure why the extra '0' is there. Upon some extra snooping about I did figure out what the extra '0' is for. If you set an ENV var called 'N' like so
EXPORT N=9
it will be placed in that last position like this
Database-Accessor-1.180509
So that little mystery solved. Unfortunately this is an undocumented feature as least in the pod. Though if you are quick enough to read the default template
{{ sprintf('%01u', ($ENV{N} || 0)) }}
you might pick this out if you happen to read Text::Template like I do. Being the sort of person that I am I had to try this will all sorts of unusual entries just so see what happens. It will take any integer and tack it on, so you could see
Database-Accessor-1.1805090210
using special characters just dies as you get a sprintf error, the same when using a string, if you use a negative number you can get some fun results like this
Database-Accessor-1.1805018446744073709551606
There is also one other undocumented feature if you can also use a 'DEV' ENV var and tack that one the end after an'_'. If you set
EXPORT N=1
EXPORT DEV=9
you would get
Database-Accessor-1.180501_009
which is neat.
You can of course change the format anyway you want. If I want my original patten '.01' and have it start at '2' rather that the default or 1, all I have to do is;
[AutoVersion]
++major = 2
++format = {{sprintf('0.%02d',$major)}}
Above I am setting the plugin attribute 'major' from the default of '1' to '2', next I set the 'format' attribute, just a simple Text::Template line where I use a sprintf to format the passed in $major attribute from the line above. So after a build I get this
Database-Accessor-0.02
It would be nice if I could get both a major and minor attribute in there but that is for another post.
So all in all a nice little plugin but a little lacking on the documentation side.
Leave a comment