package JSTAPd::Contents; use strict; use warnings; use FindBin; sub suite { $_[0]->{suite} } sub new { my($class, $name, $path) = @_; my $self = bless { name => $name, path => $path, suite => undef, }, $class; $self->parse if $path =~ /\.t$/; $self; } sub slurp { $_[0]->{slurp} ||= $_[0]->{path}->slurp } my $ANON_CLASS_COUNT = 0; sub parse { my $self = shift; my $script = $self->slurp; my $package = join '::', __PACKAGE__, 'AnonClass', 'Num'.($ANON_CLASS_COUNT++); my $code = " # line 1 $package.pm package $package; ## BEGIN{ \$$package\::IN_THE_PARSE = 1 }; # line 1 $self->{path} $script; # line 5 $package.pm sub path { '$self->{path}' } sub name { '$self->{name}' } JSTAPd::Suite::export(__PACKAGE__); 1;"; do { local $FindBin::Bin = $self->{path}->dir; eval $code; ## no critic }; $@ and die $@; $self->{suite} = $package->new; } sub header { my($self, %args) = @_; my $script = $self->suite->client_script; return sprintf <<'HTML', $args{jstapd_prefix}, $args{jstapd_prefix}, $args{jstapd_prefix}, $args{session}, $args{path}, $self->suite->tests, ($args{include} || 'nop()'), $script; HTML } sub build_html { my($self, $head, $body) = @_; my $index = $self->slurp; $body = sprintf '
%s
', $body; $index =~ s/\$HEAD/$head/g; $index =~ s{\$BODY}{$body
}g; $index; } sub build_index { my($class, %args) = @_; _default_index(%args); } sub _default_index { my %args = @_; return sprintf <<'HTML', $args{jstapd_prefix}, $args{jstapd_prefix}, $args{jstapd_prefix}, $args{jstapd_prefix}, ($args{run_once} ? 'true' : 'false'), ($args{auto_open} ? 'true' : 'false'); JSTAPd main index
./share/ | ./contents/
Test Files: 0/0
Test Plans: 0/0
HTML } 1; __END__ =head1 NAME JSTAPd::Contents - test file manager =cut