#!/usr/bin/perl

use strict;

# Perl < 5.005 does not include File::Spec (nor anything similar I'm
# aware of) so there is a quick-and-dirty (Unix only) implementation
sub BEGIN {
  if( $] < 5.005 ) {
    package File::Spec;

    sub catfile {
      shift;

      join '/', @_;
    }

    sub catdir {
      shift;

      ( join '/', @_ ) . '/';
    }

    package main;
  } else {
    require File::Spec;
  }
}

if( @ARGV == 0 ) {
  print <<EOH;
Usage: $0 sample-name

if a file named samples/sample-name/sample-name.pl exists, then
changes the directory to samples/sample-name and executes
the program (via do filename)
EOH
  exit 1;
}

my( $fname, $dir ) = ( "$ARGV[0].pl",
                       File::Spec->catdir( 'samples', $ARGV[0] ) );
my( $path ) = File::Spec->catfile( $dir, $fname );

if( -f $path ) {
  use blib;
  use Cwd;

  my( $cwd ) = getcwd();
  chdir $dir;
  my( $ret ) = do $fname;
  die "$@: $!" if $@;
  die "$!" if $!;
  # probably not necessary
  chdir $cwd;
}
else {
  die "file '$path' does not exist";
}

# Local variables: #
# mode: cperl #
# End: #
