Skip Menu |

This queue is for tickets about the Getopt-Euclid CPAN distribution.

Report information
The Basics
Id: 55259
Status: resolved
Priority: 0/
Queue: Getopt-Euclid

People
Owner: Nobody in particular
Requestors: denis.baurain [...] ulg.ac.be
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: v0.2.2



Subject: easy feature request...
Date: Fri, 5 Mar 2010 16:02:15 +0100
To: <bug-Getopt-Euclid [...] rt.cpan.org>
From: "Denis BAURAIN" <denis.baurain [...] ulg.ac.be>
Hello, I use a lot Getopt::Euclid to develop auto-documenting perl scripts for bioinformatics. It fits very well except for one thing: I cannot get the value of my version number (or even the complete string) from inside my scripts. If I had an Euclid variable containing my version number, I would print it in the headers of my output files (for logging purposes). Right now, I have to duplicate the version number in my code (in the POD and as a variable), which somewhat defeats the whole point of Euclid. Would it be difficult to implement? I guess not since it's dynamically built when using the --version argument. Please note that I have not tried yet myself as I do not have any experience with source filters. Best regards, Denis -- Denis BAURAIN, Ph.D. Unit of Animal Genomics GIGA-R & Faculty of Veterinary Medicine University of Liège GIGA Tower (B34 - 1° floor) CHU, Sart Tilman Campus 1 Avenue de l'Hopital 4000-Liège, Belgium
Created $Getopt::Euclid::SCRIPT_VERSION variable. You can also define the version at the top of your script: BEGIN { use version; our $VERSION = qv('1.2.3'); } use Getopt::Euclid; Just make sure that $VERSION is set before Getopt::Euclid's import stubroutine is called.
Subject: euclid.55259.diff
diff --git a/lib/Getopt/Euclid.pm b/lib/Getopt/Euclid.pm index 4673834..915e602 100644 --- a/lib/Getopt/Euclid.pm +++ b/lib/Getopt/Euclid.pm @@ -93,9 +93,6 @@ sub Getopt::Euclid::Importer::DESTROY { '.pm file cannot define an explicit import() when using Getopt::Euclid'; } -# Central variable to store script version for ticket #55259 -our $SCRIPT_VERSION; - sub import { shift @_; my $minimal_keys; @@ -177,11 +174,10 @@ sub import { # Extract essential interface components... my ($prog_name) = ( splitpath($0) )[-1]; - # Extract version info - ($SCRIPT_VERSION) = + my ($version) = $pod =~ m/^=head1 $VERS .*? (\d+(?:[._]\d+)+) .*? $EOHEAD /xms; - if ( !defined $SCRIPT_VERSION ) { - $SCRIPT_VERSION = $main::VERSION; + if ( !defined $version ) { + $version = $main::VERSION; } my ( $opt_name, $options ) = @@ -355,7 +351,7 @@ m/^=head1 [^\n]+ (?i: licen[sc]e | copyright ) .*? \n \s* (.*?) \s* $EOHEAD /xms {$1 $prog_name $arg_summary $2}xms; $pod =~ s{ ^(=head1 $VERS \s*) .*? (\s*) $EOHEAD } - {$1 This document refers to $prog_name version $SCRIPT_VERSION $2}xms; + {$1 This document refers to $prog_name version $version $2}xms; # Handle standard args... if ( grep { / --man /xms } @ARGV ) { @@ -374,7 +370,7 @@ m/^=head1 [^\n]+ (?i: licen[sc]e | copyright ) .*? \n \s* (.*?) \s* $EOHEAD /xms _print_and_exit($pod); } elsif ( first { $_ eq '--version' } @ARGV ) { - print "This is $prog_name version $SCRIPT_VERSION\n"; + print "This is $prog_name version $version\n"; if ($licence) { print "\n$licence\n"; } @@ -1078,14 +1074,7 @@ or: =head1 VERSION This is alpha release 1.2_34 - -You may also specify the version number in your code. However, in order for -Getopt::Euclid to properly read it, it must be in a C<BEGIN> block: - - BEGIN { use version; our $VERSION = qv('1.2.3') } - use Getopt::Euclid; - -Euclid stores the version as C<$Getopt::Euclid::SCRIPT_VERSION>. + =item =head1 REQUIRED ARGUMENTS