Index: bpkg/trunk/bpkg
===================================================================
--- bpkg/trunk/bpkg (revision 57)
+++ bpkg/trunk/bpkg (revision 58)
@@ -70,4 +70,5 @@
 EXPLICIT_PACKAGE=0
 REQUIRED_PROGRAMS='installwatch cpio perl tar bzip2 unzip gzip'
+DESCRIPTION="Automatically generated by $SELF"
 MD5SUM='none'
 
@@ -203,7 +204,27 @@
 }
 
+build_pre_python()
+{
+	if [ $EXPLICIT_PACKAGE = 0 -] && [[ $PACKAGE != py* ]]; then
+		PACKAGE=python-$PACKAGE
+	fi
+}
+
 build_python()
 {
 	python setup.py build -f
+}
+
+build_pre_perl()
+{
+	if [ $EXPLICIT_PACKAGE = 0 ] && [[ $PACKAGE != perl* ]]; then
+		PACKAGE=perl-$PACKAGE
+	fi
+}
+
+build_post_perl()
+{
+	notice "Adding Perl packlist contents to package manifest"
+	cat `find "$DESTROOT" -name .packlist` | duplicate_paths "$DESTROOT"
 }
 
@@ -228,5 +249,4 @@
 packager_slackware()
 {
-	installer
 	cd $DESTROOT
 	local out=$PKGDIR/$PACKAGE-$PACKAGEVER-i386-$PACKAGEREL.tgz
@@ -249,9 +269,11 @@
 {
 	pacman -Q "$PACKAGE" > /dev/null 2>&1 && error "package '$PACKAGE' already installed, remove it before packaging"
+	if echo "$PACKAGEVER" | grep -q -- -; then
+		PACKAGEVER=${PACKAGEVER//-/_}
+	fi
 }
 
 packager_arch()
 {
-	installer
 	local configs=`(cd $DESTROOT && find etc -type f) 2> /dev/null`
 	local deps=`(cd $DESTROOT && find . -type f | xargs --no-run-if-empty file | grep 'ELF.*executable' | cut -d: -f1 | xargs --no-run-if-empty ldd 2> /dev/null | awk '{print $3}' | grep ^/ | xargs --no-run-if-empty pacman -Qo 2> /dev/null | awk '{print $5}' | sort | uniq) 2> /dev/null`
@@ -263,5 +285,5 @@
 	pkgver=$PACKAGEVER
 	pkgrel=$PACKAGEREL
-	pkgdesc="Automatically generated by $SELF"
+	pkgdesc="$DESCRIPTION"
 	url="http://swapoff.org/$SELF"
 	depends=($deps)
@@ -290,5 +312,4 @@
 packager_gentoo()
 {
-	installer
 	#local deps=`(cd $DESTROOT && find . -type f | xargs --no-run-if-empty file | grep 'ELF.*executable' | cut -d: -f1 | xargs --no-run-if-empty ldd 2> /dev/null | awk '{print $3}' | grep ^/ | xargs --no-run-if-empty pacman -Qo 2> /dev/null | awk '{print $5}' | sort | uniq) 2> /dev/null`
 	ls -d /usr/portage/*/$PACKAGE > /dev/null 2>&1 && error "Package '$PACKAGE' already exists in portage."
@@ -376,6 +397,20 @@
 quitloop=0
 while [ $quitloop = 0 -a $# != 0 ]; do
-	if [[ -f "$1" || "$1" = ftp://* || "$1" = http://* ]]; then
-		AUTOEXTRACT="$1"
+	TARGET="$1"
+	if [[ "$TARGET" = cpan://* ]]; then
+		CPAN_MODULE=`basename "$TARGET"`
+		notice "Attempting to download CPAN module $CPAN_MODULE"
+		TARGET=`perl -MCPAN -e "get '$CPAN_MODULE'" | grep Checksum | awk '{print $3}'`
+		test -f "$TARGET" || error "failed to fetch $CPAN_MODULE from CPAN, try 'perl -MCPAN -e \"get '$CPAN_MODULE'\""
+		PACKAGE=`echo "$CPAN_MODULE" | sed -e 's/:\\+/-/g' | tr A-Z a-z`
+		if [[ $PACKAGE != perl-* ]]; then
+			PACKAGE=perl-$PACKAGE
+		fi
+		PACKAGEVER=`perl -MCPAN -e "print CPAN::Shell->m(\"$CPAN_MODULE\")" | grep CPAN_VERSION | awk '{print $2}'`
+		EXPLICIT_PACKAGE=1
+	fi
+
+	if [[ -f "$TARGET" || "$TARGET" = ftp://* || "$TARGET" = http://* ]]; then
+		AUTOEXTRACT="$TARGET"
 		if [[ "$AUTOEXTRACT" == *bz2 || "$AUTOEXTRACT" == *tbz ]]; then
 			FLAGS=j
@@ -424,5 +459,5 @@
 		fi
 	else
-		case $1 in
+		case $TARGET in
 			--version)
 				echo $VERSION
@@ -457,4 +492,7 @@
     obtained by extracting the package name and version from the package
     source directory name.
+  --description=<description>
+    Specify a package description. Default is 'Automatically generated by
+    bpkg'.
   --unique
     Pass options to autoconf to install into configuration and data directories
@@ -471,13 +509,16 @@
     Verify that the source file has the given MD5 checksum.
 
-For further information, including examples, visit http://swapoff.org/bpkg
+For further information including examples, visit http://swapoff.org/bpkg
 EOF
 				exit 0
 			;;
+			--description=*)
+				DESCRIPTION=`echo "$TARGET" | cut -d= -f2-`
+			;;
 			--install-with=*)
-				INSTALLER=`echo "$1" | cut -d= -f2-`
+				INSTALLER=`echo "$TARGET" | cut -d= -f2-`
 			;;
 			--build-with=*)
-				CUSTOMBUILDER=`echo "$1" | cut -d= -f2-`
+				CUSTOMBUILDER=`echo "$TARGET" | cut -d= -f2-`
 				BUILDER=custom
 			;;
@@ -486,14 +527,14 @@
 			;;
 			--prefix=*)
-				PREFIX=`echo $1 | cut -d= -f2-`
+				PREFIX=`echo $TARGET | cut -d= -f2-`
 			;;
 			--sysconfdir=*)
-				SYSCONFDIR=`echo $1 | cut -d= -f2-`
+				SYSCONFDIR=`echo $TARGET | cut -d= -f2-`
 			;;
 			--localstatedir=*)
-				LOCALSTATEDIR=`echo $1 | cut -d= -f2-`
+				LOCALSTATEDIR=`echo $TARGET | cut -d= -f2-`
 			;;
 			--datadir=*)
-				DATADIR=`echo $1 | cut -d= -f2-`
+				DATADIR=`echo $TARGET | cut -d= -f2-`
 			;;
 			--unique)
@@ -504,13 +545,13 @@
 			;;
 			--package=*)
-				PACKAGE=`echo "$1" | cut -d= -f2- | rev | cut -d- -f2- | rev`
-				PACKAGEVER=`echo "$1" | cut -d= -f2- | rev | cut -d- -f1 | rev`
+				PACKAGE=`echo "$TARGET" | cut -d= -f2- | rev | cut -d- -f2- | rev`
+				PACKAGEVER=`echo "$TARGET" | cut -d= -f2- | rev | cut -d- -f1 | rev`
 				EXPLICIT_PACKAGE=1
 			;;
 			--packager=*)
-				PACKAGER=`echo $1 | cut -d= -f2-`
+				PACKAGER=`echo $TARGET | cut -d= -f2-`
 			;;
 			--md5=*)
-				MD5SUM=`echo $1 | cut -d= -f2-`
+				MD5SUM=`echo $TARGET | cut -d= -f2-`
 			;;
 			*)
@@ -526,8 +567,18 @@
 
 if [ $EXPLICIT_PACKAGE = 0 ]; then
-	# Always use Python distutils data if available
+	# Use Python distutils data if available
 	if [ -r setup.py ]; then
-		PACKAGE=`python setup.py --name | tr A-Z a-z`
-		PACKAGEVER=`python setup.py --version`
+		if [[ $PACKAGE != py* ]]; then
+			PACKAGE=`python setup.py --name | tail -1 | tr A-Z a-z`
+		fi
+		PACKAGEVER=`python setup.py --version | tail -1`
+	fi
+	# Use MakeMaker data if available
+	if [ -r Makefile.PL ]; then
+		OLDVER=$PACKAGEVER
+		PACKAGEVER=`PERL_MM_USE_DEFAULT=1 perl -e 'do "Makefile.PL"; print $VERSION' | tail -1`
+		if [[ $PACKAGEVER != [0-9]*.* ]]; then
+			PACKAGEVER=$OLDVER
+		fi
 	fi
 	if [ "_$PACKAGE" = "_$PACKAGEVER" ]; then
@@ -544,4 +595,6 @@
 	elif [ -x autogen.sh ]; then
 		BUILDER=autogen
+ 	elif [ -r Makefile.PL ]; then
+ 		BUILDER=perl
 	elif [ -r Imakefile ]; then
 		BUILDER=xmkmf
@@ -554,6 +607,4 @@
 		BUILDER=python
 		INSTALLER='python setup.py install -f'
-	elif [ -r Makefile.PL ]; then
-		BUILDER=perl
 	elif [ -r $PACKAGE.pro ]; then
 		BUILDER=qmake
@@ -563,8 +614,20 @@
 fi
 
+declare -F build_pre_$BUILDER > /dev/null && eval build_pre_$BUILDER
+
+declare -F packager_pre_$PACKAGER > /dev/null && eval packager_pre_$PACKAGER
+declare -F packager_$PACKAGER > /dev/null || error "no such function packager_$PACKAGER()"
+
 if [ $SKIPBUILD = 0 ]; then
+	notice "Running $BUILDER builder"
 	eval build_$BUILDER || error "build failed"
 fi
 
+notice "Installing package"
+installer
+
+declare -F build_post_$BUILDER > /dev/null && eval build_post_$BUILDER
+
+notice "Running $PACKAGER packager"
 eval packager_$PACKAGER
 
