1#!/usr/local/bin/perl -w 2 3################################################################################# 4# 5# Perl module checker 0.0.3 6# 7################################################################################# 8# 9# This Perl script checks for installed modules by trying to 'use' the 10# module. If the check fails, then the module is not present. 11# 12# If you want to install additional modules, use: 13# > perl -MCPAN -e shell 14# > install [module name] 15# 16# If the first one fails, please install the perl-CPAN package first 17# 18# Upgrade CPAN if possible: 19# > install Bundle::CPAN 20# > reload cpan 21# 22# Digest modules: 23# > install Digest::MD5 24# > install Digest::SHA 25# > install Digest::SHA1 26# > install Digest::SHA256 27# 28 29################################################################################# 30 31use strict; 32 33my $check = "0"; 34 35# Modules to check 36my @modCheck = qw( 37Digest::MD5 38Digest::SHA 39Digest::SHA1 40Digest::SHA256 41); 42 43# Use command-line module names if present. 44@modCheck = @ARGV if (@ARGV); 45 46for (@modCheck) 47 { 48 if (installed("$_")) 49 { 50 print "$_ installed (version ",$check,").\n" 51 } 52 else 53 { 54 print "$_ NOT installed.\n" 55 } 56 } 57 58######################################### 59# 60# SUB: Installed modules 61# 62######################################### 63 64sub installed 65 { 66 67 my $module = $_; 68 69 # Try to use the Perl module 70 eval "use $module"; 71 72 # Check eval response 73 if ($@) 74 { 75 # Module is NOT installed 76 $check = 0; 77 } 78 else 79 { 80 # Module is installed (reset module version to '1') 81 $check = 1; 82 83 my $version = 0; 84 # Try to retrieve version number (by using eval again) 85 eval "\$version = \$$module\::VERSION"; 86 87 # Set version number if no problem occurred 88 $check = $version if (!$@); 89 } 90 91 # Return version number 92 return $check; 93} 94 95 96exit(); 97 98# The end 99