
# script tag not needed, just in for IIS Compat test
<script runat=server>

use lib '.';	
use T;	
use strict;
use vars qw($Application $Session $t $Deep);
use Carp qw(confess);

$SIG{__DIE__} = \&confess;

sub Application_OnStart {
    $Application->{Start} = 1;
}

sub Session_OnStart {
    $Session->{Count} = 10;
}

sub Script_OnStart {
    $t = T->new();
}

sub Script_OnEnd {
    $t->done;
}

sub my::tag {
    $t->eok($Deep, 'Deep tag not evaluated');
}

sub my::deeptag {
    $t->ok;
    $Deep++;
}

sub my::returnok {
    $t->eok($_[1] eq 'ok', 'String return');
}

sub my::args {
    $t->eok($_[0]->{ok}, $_[0]->{error} || "Argument passing");
}

# CLEANUP old state files from previous test script runs
# so things like Application_OnStart may run
if($0 =~ m|application\.t$|) {
#    print STDERR "-- ASP State Initialization for Tests --\n";
    die unless (-e '../t');
    my @dirs = ('.state');
    my @delete_dirs;
    while(@dirs) {
	my $dir = shift @dirs;
	next unless -d $dir;
	opendir(DIR, $dir);
	for(readdir(DIR)) {	
	    next if /^\.\.?$/;
	    my $file = "$dir/$_";
	    if(-d $file) {
		push(@dirs, $file);
	    } elsif(-e $file) {
		unlink($file);
	    } else {
		die("$file does not exist, but we just read it");
	    }
	}
	unshift(@delete_dirs, $dir);
    }
    for(@delete_dirs) {
	rmdir($_);
    }
}

# script tag not needed, just in for IIS Compat test
</script>
