# -*-sh-*-

set_mst_envs
get_perl_exe
set_perl_environment

export HOME="$MST_SIMUL_ROOT"

PERL5LIB="$MST_OTS_ROOT/import/perl:$PERL5LIB"

eval $($PERL -V:bin)

if [ ! -x $bin/cpan ]; then

   echo >&2 "$0: unable to find real cpan"
   exit 1

fi


# if the things on the command line are files on the local system,
# use cpaninject to put them into the local sources tree and use
# cpan to install them (and their dependencies)

args=()
for thing in "$@" ; do

    if [ -f "$thing" ]; then

	if [[ "$thing" =~ Bundle/(.*)\.pm ]] ; then

	    thing="Bundle::${BASH_REMATCH[1]}"

	else

	    cpaninject $thing

	    thing="LOCAL/$(basename $thing)"

	fi

    fi

    args[${#args[*]}]="$thing"

done


exec $PERL $bin/cpan ${1+"${args[@]}"}

# just in case
exit 1


