package testpack; sub new { my $ppref = {}; my $instance = { TSTPRFL => $ppref }; %$ppref = ( configid => { good => { 'identifier' => [ { 'goodconfig' => 0}, ], }, bad => { 'identifier' => [ { '987nonexist789' => 13}, ], }, }, fileonly => { good => { 'file' => [ {'testfilename.tst' => 0}, ] }, bad => { '/usr/bin/perl' => '', '987nonexist789.tst' => 1, }, }, fullpath1 => {good => { '/home/me/testfiles/testfilename.tst' => 0, }, bad => { '987nonexist789.tst' => 1, 'testfilename.tst' => '', }, }, # and so on for all testcases ); return bless $instance; } sub tst { my $self = shift; my %opts = @_; my $script = $opts{ script }; $self -> infest( $opts{ options } ); $self -> { options } = $opts{ options }; do { $self -> tstCombi; } while( $self -> nextCombi ); } sub tstCombi { my $self = shift; # the combination to be tested here is # indicated by the current mask values in the # test configuration structure you created and # then infested with combination registers and maxima } sub infest { # infest a structure with combination registers # and pre-count each set for efficiency and store its max of 2**N-1 my $self = shift; my $ref = shift; my $count = 0; if ( ref( $ref ) eq 'HASH' ) { while ( my ( $k, $v ) = each %$ref ) { $self -> infest( $v ); $k =~ /^\_/ or $count++; } $ref -> { _reserved_combi } = 0; $ref -> { _reserved_limit } = (2**$count) - 1 ; } elsif ( ref( $ref ) eq 'ARRAY' ) { for my $v ( @$ref ) { $self -> infest( $v ); ref( $v ) eq 'SCALAR' and $count++; } push @$ref, { _reserved_combi => 0, _reserved_limit => ( 2 ** $count ) - 1 }; } } sub nextCombi { my $self = shift; $self -> increment ( $self -> { options } ); } sub increment { my $self = shift; my $node = shift; if ( ref( $node ) eq 'HASH' ) { for my $k ( sort ( grep !/^\_/, ( keys %$node ))) { $self -> increment( $node -> { $k } ) and return 1; } if ( $node -> { _reserved_combi } == $node -> { _reserved_limit } ) { return ( $node -> { _reserved_combi } = 0 ); } else { return ( $node -> { _reserved_combi } ++ ); } elsif ( ref( $node ) eq 'ARRAY' ) { if ( $node -> [ $#node ]{ _reserved_combi } == $node -> [ $#node ]{ _reserved_limit } ) { return ( $node -> [ $#node ]{ _reserved_combi } = 0 ); } else { return ( $node -> [ $#node ]{ _reserved_combi } ++ ); } } die "something went wrong with the structure"; } 1;