#!/bin/bash
#
# The script automatically obtain Perl modules and their local version
# in set directory (recursively)
#

if [[ -z $1 || ! -d $1 ]]; then
	echo "Usage: ${0##*/} <directory>"
	echo
	echo "Example: ${0##*/} ../src/warden-server/"
	exit 1
fi

modules_file="/tmp/warden-modules.txt"
sed '/^use [A-Z]/!d; /Warden/d' $(find $1 -type f) 2>/dev/null | cut -f 2 -d " " | sed 's/;//' | sort -u | \
while read module;
do
	perl -e "eval { require $module; }; if (\$@) { print \"$module: version not found\n\"; } else { print \"$module >= \$$module::VERSION\n\"}"
done

# cleanup section
rm -f "$modules_file"

exit 0
