Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

create $VERSION from the modtime of the file

by merlyn (Sage)
on Dec 27, 2004 at 18:45 UTC ( [id://417605]=CUFP: print w/replies, xml ) Need Help??

The $VERSION of a module needs to be monotonically increasing for new releases. This snippet can be placed into a module to create a version number that depends on the modification time of the module, calculated in GMT, in a human-readable format as YYYYMMDD.HHMMSS. The only problem you'll have is if you release two different releases within the same second. Slow down. {grin}
## the following code must be all on one line: $VERSION = sub { sprintf "%04d%02d%02d.%02d%02d%02d", 1900+$_[5], 1+$_ +[4], @_[3,2,1,0] }->(gmtime +(stat __FILE__)[9]);

Replies are listed 'Best First'.
Re: create $VERSION from the modtime of the file
by The Mad Hatter (Priest) on Dec 27, 2004 at 18:53 UTC
        Are you sure? I don't think Safe.pm will like the stat.
Re: create $VERSION from the modtime of the file
by legato (Monk) on Dec 27, 2004 at 20:34 UTC

    While I understand the desire to be Lazy, wouldn't it be sufficient to use a script like:

    #!/usr/bin/perl -w use strict; for (glob '*.pm') { my $ver = sub { sprintf "%04d%02d%02d.%02d%02d%02d", 1900+$_[5], 1+$_[4], @_[3,2,1,0] }->(gmtime +(stat $_)[9]); open IN, '<', $_ or die "Failed to update $_ to $ver"; open OUT, '>' "$_.new" or die "Failed to create $_.new"; while (<IN>) { s:^((our|my|local)\s+)$VERSION\.+=\.+\;:\$VERSION = $ver\;:; print OUT $_; } close IN; close OUT; unlink $_; rename ("$_.new", $_); }
    ((untested, but you get the idea))?

    In this form, it would update $VERSION for all modules in the current directory. I use something like this (more complex, as it updates many things for company code standards), and have had no trouble at all.

    Anima Legato
    .oO all things connect through the motion of the mind

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://417605]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-19 21:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found