#!/bin/sh

_tidy() {
    (
    file="$1"
    [ -e "$file" ] || return 1
    find $file \
        \( -name '*.pm' -o -name '*.pl' -o -name '*.t' \) \
        -print -exec perltidy -b {} \; \
      | xargs -n 1 echo 'TIDY:'

    find $file \
        \( -name '*.bak' -o -name '*~' \) \
        -print -exec rm -f {} \; \
      | xargs -n 1 echo '  RM:'
    ) >&2
}

if [ -z "$1" ]; then
    _tidy bin
    _tidy lib
    _tidy t
    _tidy scripts
else
    while [ -n "$1" ]; do
        _tidy "$1"
        shift
    done
fi

