Skip to content

Instantly share code, notes, and snippets.

@lsiden
Last active July 18, 2018 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lsiden/92b0c08cc841dc4f01a3e4246fca28c5 to your computer and use it in GitHub Desktop.
Save lsiden/92b0c08cc841dc4f01a3e4246fca28c5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Make CPAN package.
# Usage: mkcpanpkg $dirname
# Run this in the parent directory of $dirname.
# $dirname must be a Git repository.
# It will create a file $dirname-$version.tar.gz containing all files tracked by Git.
function modname() {
perl -e "print join(q{::}, split(/-/, qw{$1}))"
}
function version() {
local -r PKG=$1
local -r MODULE=$2
perl -I $PKG/lib -M${MODULE} -e "print \$${MODULE}::VERSION"
}
function lsFiles() {
local -r PKG=$1
sed -e "s/^/$PKG\//" < $PKG/MANIFEST
}
if [ $# -lt 1 ]; then
>&2 echo "Usage: $(basename $0) name version"
exit 1
fi
PKG=$1
MODULE=$(modname $PKG)
VERSION=$(version $PKG $MODULE)
if [ -z $VERSION ]; then
>&2 echo "First define \$${MODULE}::VERSION."
exit 1
fi
set -x
lsFiles $PKG | tar -cvzf ${PKG}-${VERSION}.tar.gz --exclude=.git/ --files-from -
#!/usr/bin/env bash
# Print a list of Perl modules used by files and all sub-directories.
# See grep -r ...
if [ $# -lt 1 ] ; then
>2& echo "Usage: $(basename $0) files..."
exit 1
fi
function strip() {
sed -E -e 's/^[^:]*:use ([a-zA-Z0-9:]*).*/\1/'
}
function filter() {
egrep -v -e '\buse (strict|warnings|lib)'
}
grep -e '^use ' -R $* | filter | strip | sort -u
#!/usr/bin/env bash
# Print the version number of an installed Perl module.
# This may depend on having PERL5LIB defined in your environment.
readonly MODULE=$1
perl -M$MODULE -le "print \$${MODULE}::VERSION"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment