CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
Reading installed perl module version from aperl module file

 



subhesh
New User

May 12, 2015, 4:13 AM

Post #1 of 4 (5527 views)
Reading installed perl module version from aperl module file Can't Post

Hi All,

Can anyone please help me out to fetch perl module version from a particular ".pm" file.

for example:

I have an installed perl module file:

"/usr/software_series/testing/share/perl5.14_temp/lib/perl5/Lucy/Docs/FileLocking.pm"

then I want to fetch the module version from this file.

Note: I tried Module::Metadata utility but its not working for few perl modules.

My script::

use strict;
use warnings;
use Module::Metadata;
my $file = "/usr/software/test/share/perl5.14_temp/lib/perl5/Lucy/Docs/FileLocking.pm";

# information about a .pm file
my $info = Module::Metadata->new_from_file($file);
my $version = $info->version;
print ("\nVersion found:: $version \n");



But above script is not able to fetch back version value.

Please help!!


Laurent_R
Veteran / Moderator

May 12, 2015, 10:10 AM

Post #2 of 4 (5517 views)
Re: [subhesh] Reading installed perl module version from aperl module file [In reply to] Can't Post

Perhaps you could try to print the $FileLocking::VERSION variable.But check in the module code if it exists and if it is really all uppercase.


subhesh
New User

May 12, 2015, 10:57 PM

Post #3 of 4 (5509 views)
Re: [Laurent_R] Reading installed perl module version from aperl module file [In reply to] Can't Post

Thanks for reply.

I tried below script to get $Version value from ".pm" file.
But getting VERSION value as null.

Script::

#!/usr/bin/perl
# this is implicitly package main
use lib 'usr::software::test::share::perl5.14_temp::lib::perl5::Lucy::Docs::FileLocking'; # imports $var

print "var = $VERSION \n"; # access the variable without prefix

Output:: var =



Actual .pm file content::

use Lucy;
our $VERSION = '0.004002';
$VERSION = eval $VERSION;

1;

Please suggest.


FishMonger
Veteran / Moderator

May 13, 2015, 4:38 PM

Post #4 of 4 (5487 views)
Re: [subhesh] Reading installed perl module version from aperl module file [In reply to] Can't Post


Quote
use lib /usr::software::test::share::perl5.14_temp::lib::perl5::Lucy::Docs::FileLocking'; # imports $var

Wrong.

The lib pragma expects a directory path as its arg without the filename. And based on the module code you posted, even if you remove the filename from that statement, it still couldn't import the $var variable since it doesn't exist.

Your module code is even missing the package declaration, so it's not a true module. It is a library file/script.

Here's how to do it without using Exporter to export $VERSION

Code
package FileLocking; 

use strict;
use warnings;

our $VERSION = '0.004002';

1;



Code
#!/usr/bin/perl 

use strict;
use warnings;
use lib '/usr/software/test/share/perl5.14_temp/lib/perl5/Lucy/Docs';
use FileLocking;

print "var = $FileLocking::VERSION";


This is how you'd do it when using Exporter to export $VERSION.

Code
package FileLocking; 

use strict;
use warnings;
use Exporter;

our @ISA = qw(Exporter);
our @EXPORT_OK = qw($VERSION);
our $VERSION = '0.004002';

1;



Code
#!/usr/bin/perl 

use strict;
use warnings;
use lib '/usr/software/test/share/perl5.14_temp/lib/perl5/Lucy/Docs';
use FileLocking qw($VERSION);

print "var = $VERSION";


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives