--- a/examples/03_mldbm.pl
+++ b/examples/03_mldbm.pl
@@ -1,10 +1,6 @@
-my ($tmp);
-use IO::File;
-use POSIX qw(tmpnam);
-do { $tmp = tmpnam() ;  } until IO::File->new ($tmp, O_RDWR|O_CREAT|O_EXCL);
-
-END { unlink ($tmp) || warn "cannot unlink tmp file '$tmp'"; }
+use File::Temp qw(tempfile tempdir);
 
+my ($fh, $tmp) = tempfile;
 {
     use TM::Materialized::MLDBM;
     my $tm = new TM::Materialized::MLDBM (file => $tmp);
--- a/examples/04_mldbm2.pl
+++ b/examples/04_mldbm2.pl
@@ -1,12 +1,8 @@
-my ($tmp);
-use IO::File;
-use POSIX qw(tmpnam);
-do { $tmp = tmpnam() ;  } until IO::File->new ($tmp, O_RDWR|O_CREAT|O_EXCL);
-
-END { unlink ($tmp) || warn "cannot unlink tmp file '$tmp'"; }
-
+use File::Temp qw(tempfile tempdir);
 use Data::Dumper;
 
+my ($fh,$tmp) = tempfile;
+
 # look ma, no hands!
 
 warn "file $tmp";
--- a/t/013index.t
+++ b/t/013index.t
@@ -12,6 +12,7 @@ use Data::Dumper;
 $Data::Dumper::Indent = 1;
 
 use Time::HiRes;
+use File::Temp qw(tempfile tempdir);
 
 use TM;
 use TM::Literal;
@@ -311,11 +312,8 @@ if (DONE) {
 my @tmp;
 
 sub _mktmps {
-    foreach (qw(0)) {
-	use IO::File;
-	use POSIX qw(tmpnam);
-	do { $tmp[$_] = tmpnam() ;  } until IO::File->new ($tmp[$_], O_RDWR|O_CREAT|O_EXCL);
-    }
+	my ($fh,$tfn) = tempfile;
+	$tmp[0] = $tfn;
 }
 
 _mktmps;
--- a/t/015indexable.t
+++ b/t/015indexable.t
@@ -5,6 +5,7 @@ use Data::Dumper;
 $Data::Dumper::Indent = 1;
 
 use Time::HiRes;
+use File::Temp qw(tempfile tempdir);
 
 use TM;
 
@@ -221,7 +222,7 @@ if (DONE) { # lazy index, built by use,
     ok (eq_set ([ qw(superclass.type class.type instance.type subclass.type) ],
                 [ keys %s ]), 'axes');
 
-    map { ok ($_->{hits}     == 0, 'stat hits') 
+    map { ok ($_->{hits}     == 0, 'stat hits')
        && ok ($_->{requests} == 0, 'stat requests') }
     values %s;
 
@@ -380,13 +381,10 @@ if (DONE) {
 }
 
 
-sub _mktmp {
-    my $tmp;
-
-    use IO::File;
-    use POSIX qw(tmpnam);
-    do { $tmp = tmpnam() ;  } until IO::File->new ($tmp, O_RDWR|O_CREAT|O_EXCL);
-    return $tmp;
+sub _mktmp
+{
+	my ($fh, $tfn) = tempfile();
+	return ($tfn);
 }
 
 if (DONE) { # does it work together with a MLDBM backed map?
@@ -504,7 +502,7 @@ if (DONE) {
 	implant ($tm, $taxo);
 
 	my $idx = new TM::Index::Match ($tm, cache => \%cache);
-    
+
 #	warn "\n# verifying first run, should be medium fast";
 	my $start = Time::HiRes::time;
 	verify ($tm, $taxo, 1);
@@ -519,7 +517,7 @@ if (DONE) {
 	ok ($indexed < $unindexed, "measurable speedup with persistent index ($indexed < $unindexed)");
 
 #	warn "# ====== total time =============== ".(Time::HiRes::time - $start);
-	
+
 	untie %cache;
     }
 
@@ -534,7 +532,7 @@ if (DONE) {
 	implant ($tm, $taxo);
 
 	my $idx = new TM::Index::Match ($tm, cache => \%cache);
-    
+
 #	warn "\n# re-verifying second run, should be as fast";
 	my $start = Time::HiRes::time;
 	verify ($tm, $taxo, 1);
@@ -542,7 +540,7 @@ if (DONE) {
 	ok ($indexed < $unindexed, "measurable speedup with persistent index ($indexed < $unindexed)");
 
 #	warn "# ====== total time =============== ".(Time::HiRes::time - $start);
-	
+
 	untie %cache;
     }
 
@@ -550,4 +548,3 @@ if (DONE) {
 
 
 __END__
-
--- a/t/021ctmdeserialize.t
+++ b/t/021ctmdeserialize.t
@@ -6,6 +6,8 @@ use constant DONE => 1;
 # change 'tests => 1' to 'tests => last_test_to_print';
 use Test::More qw(no_plan);
 
+use File::Temp qw(tempfile tempdir);
+
 use Data::Dumper;
 $Data::Dumper::Indent = 1;
 
@@ -1077,1681 +1079,3 @@ if (DONE)
 }
 
 
-__END__
-
-
-
-3.7.1. Singe line comment
--------------------------
-
-    ::ctm
-    # a single line with comments
-
-
-3.7.2. Multiline comment
-------------------------
-
-	::ctm
-    #( one comment
-     line 2
-    )#
-
-
-
-  map reify
-
-  wildcard
-
-
-
-
-__END__
-
-
-require_ok( 'TM::Materialized::LTM' );
-
-{
-  my $tm = new TM::Materialized::LTM (inline => '
-');
-
-  ok ($tm->isa('TM::Materialized::Stream'),  'correct class');
-  ok ($tm->isa('TM::Materialized::LTM'),   'correct class');
-
-}
-
-{ # comments
-    my $ms = _parse (q|
-[ aaa ]
-
-/* some comment [ bbb ] 
-
-*/
-
-[ ccc ]
-|);
-#warn Dumper $ms;
-    ok ($ms->tids ('aaa'), 'comment: outside');
-    ok (!$ms->tids ('bbb'), 'comment: inside');
-    ok ($ms->tids ('ccc'), 'comment: outside');
-}
-
-die_ok (q{
-/*  [ aaa ]
-     */  */ 
-}, 'unparseable', 'invalid comment nesting');
-
-{ # encoding
-    my $ms = _parse (q|
-
-@"utf-8"
-
-[ aaa ]
-
-|);
-ok (1, 'encoding: ignored');
-}
-
-{ # topic address
-    my $ms = _parse (q|
- [aaa % "urn:aaa" ]
-|);
-#    warn Dumper $ms;
-    is ($ms->tids ('aaa'), $ms->tids ('urn:aaa'), 'reification: subject identifier ok');
-}
-
-
-{ # subject indicators
-    my $ms = _parse (q|
- [aaa % "urn:aaa" @ "urn:xxx" @ "urn:yyy" ]
-|);
-#    warn Dumper $ms;
-
-    ok (eq_set ($ms->midlet ($ms->tids ('urn:aaa'))->[TM->INDICATORS],
-		[ 'urn:xxx', 'urn:yyy' ]),                          'indication: all found');
-}
-
-{ # topics types
-    my $ms = _parse (q|
- [aaa: bbb ccc ]
-|);
-#warn Dumper $ms;
-
-    my @res = $ms->match (TM->FORALL, type => 'isa', irole => 'instance', iplayer => 'tm:aaa');
-    ok (eq_set ([ map { $_->[TM->PLAYERS]->[0]  } @res ],
-		[ 'tm:bbb', 'tm:ccc' ]), 'topic: class values');
-}
-
-{ # topic basename
-    my $ms = _parse (q|
- [aaa: bbb ccc = "AAA" ]
-|);
-#warn Dumper $ms;
-
-    ok (eq_set ([ map { $_->[0] } map { $_->[TM->PLAYERS]->[1] } $ms->match (TM->FORALL, type => 'name', iplayer => 'tm:aaa' ) ] ,
-		[ 'AAA' ]), 'topic: AAA basename');
-}
-
-{ # topic scoped basename
-   my $ms = _parse (q|
-[aaa: bbb ccc = "AAAS" / sss ]
-		    |);
-#warn Dumper $ms;
-    ok (eq_set ([ map {$_->[0]}  map { $_->[TM->PLAYERS]->[1] } $ms->match (TM->FORALL, scope => 'tm:sss', type => 'name', iplayer => 'tm:aaa' ) ] ,
-		[ 'AAAS' ]), 'topic: AAA basename (scoped)');
-
-    ok (scalar $ms->match (TM->FORALL, type => 'isa', irole => 'instance', iplayer => 'tm:sss' ) == 1, 'scope isa scope');
-}
-
-{ # topic, basename, sortname
-my $ms = _parse (q|
-[aaa: bbb ccc = "AAA" ; "SORTAAA" ]
-
-[xxx: yyy = "XXX";  "SORTXXX"; "DISPXXX" ]
-
-[uuu = "UUU";  "SORTUUU"; "DISPUUU" ]
-
-[vvv = "VVV";  "SORTVVV"; "DISPVVV" / sss ]
-|);
-#warn Dumper $ms;
-    ok (eq_set ([ map {$_->[0]} map { $_->[TM->PLAYERS]->[1] } $ms->match (TM->FORALL, type => 'name', iplayer => 'tm:aaa' ) ] ,
-		[ 'AAA' ]), 'topic: AAA basename');
-#    ok (eq_set ([ map {$_->[0]} map { $_->[TM->PLAYERS]->[1] } $ms->match (TM->FORALL, type => 'name', iplayer => 'tm:aaa' ) ] ,
-#		[ 'SORTAAA' ]), 'topic: SORTAAA basename');
-}
-
-{ # topic external occurrence (typed)
-    my $ms = _parse (q|
-{aaa, bbb, "http://xxxt/" }
-		  |);
-#warn Dumper $ms;
-  ok (eq_set ([ map {$_->[0]} map { $_->[TM->PLAYERS]->[1] } $ms->match (TM->FORALL, type => 'tm:bbb',        iplayer => 'tm:aaa' ) ] ,
-	      [ 'http://xxxt/' ]), 'topic: occurr typed');
-  ok (eq_set ([ map {$_->[0]} map { $_->[TM->PLAYERS]->[1] } $ms->match (TM->FORALL, type => 'occurrence', iplayer => 'tm:aaa' ) ] ,
-	      [ 'http://xxxt/' ]), 'topic: occurr (typed)');
-}
-
-
-# untyped is not allowed in LTM?
-
-{ # topic internal occurrence
-    my $ms = _parse (q|
-{aaa, bbb, [[http://xxxt/]] }
-		  |);
-#warn Dumper $ms;
-  ok (eq_set ([ map {$_->[0]} map { $_->[TM->PLAYERS]->[1] } $ms->match (TM->FORALL, type => 'tm:bbb',        iplayer => 'tm:aaa' ) ] ,
-	      [ 'http://xxxt/' ]), 'topic: int occurr typed');
-  ok (eq_set ([ map {$_->[0]} map { $_->[TM->PLAYERS]->[1] } $ms->match (TM->FORALL, type => 'occurrence', iplayer => 'tm:aaa' ) ] ,
-	      [ 'http://xxxt/' ]), 'topic: int occurr (typed)');
-}
-
-{ # mix occurrences with topics
-    my $ms = _parse (q|
-[ aaa : bbb ]
-{ aaa, xxx, "http://xxx/" }
-
-{ ccc, yyy, "http://yyy/" }
-[ ccc : ddd ]
-
-|);
-
-#warn Dumper $ms;
-
-   ok (scalar $ms->match (TM->FORALL, type => 'isa', irole => 'instance', iplayer => 'tm:aaa' ) == 1, 'topic+occur: class');
-   ok (scalar $ms->match (TM->FORALL, type => 'isa', irole => 'instance', iplayer => 'tm:ccc' ) == 1, 'topic+occur: class');
-
-   ok (eq_set ([ map {$_->[0]} map { $_->[TM->PLAYERS]->[1] } $ms->match (TM->FORALL, type => 'occurrence', iplayer => 'tm:aaa' ) ] ,
-	       [ 'http://xxx/' ]), 'topic+occur: occurr');
-   ok (eq_set ([ map {$_->[0]} map { $_->[TM->PLAYERS]->[1] } $ms->match (TM->FORALL, type => 'occurrence', iplayer => 'tm:ccc' ) ] ,
-	       [ 'http://yyy/' ]), 'topic+occur: occurr');
-}
-
-#-- assocs --------------
-
-{
-    my $ms = _parse (q|
-aaa (play1: role1, play2: role2)
-
-bbb (play1: role1, play2: role2)
-
-ccc (play1, play2: role2)
-|);
-#warn Dumper $ms;
-
-    my @res = $ms->match (TM->FORALL, type => 'tm:aaa');
-    ok (eq_set ([ map { @{$_->[TM->PLAYERS]}  } @res ],
-		[ 'tm:play1', 'tm:play2' ]), 'assoc: players');
-    ok (eq_set ([ map { @{$_->[TM->ROLES]}  } @res ],
-		[ 'tm:role1', 'tm:role2' ]), 'assoc: roles');
-
-       @res = $ms->match (TM->FORALL, type => 'tm:bbb');
-    ok (scalar @res == 1, 'assoc: separate');
-
-
-       @res = $ms->match (TM->FORALL, type => 'tm:ccc');
-    ok (eq_set ([ map { @{$_->[TM->PLAYERS]}  } @res ],
-		[ 'tm:play1', 'tm:play2' ]), 'assoc: players');
-    ok (eq_set ([ map { @{$_->[TM->ROLES]}  } @res ],
-		[ 'thing', 'tm:role2' ]), 'assoc: roles (default)');
-}
-
-{ # scoped assoc
-    my $ms = _parse (q|
-aaa (play1: role1, play2: role2) / sss
-
-aaa (play1: role1, play2: role2)
-
-aaa (play1: role1, play2: role2) / ttt
-
-		     |);
-##warn Dumper $ms;
-
-    my @res = $ms->match (TM->FORALL, type => 'tm:aaa');
-    ok (scalar @res == 3, 'scoped mixed assoc: number');
-
-    ok (grep ($_->[TM->SCOPE] eq 'tm:ttt', @res), 'scoped mixed assoc: scoping');
-    ok (grep ($_->[TM->SCOPE] eq 'tm:sss', @res), 'scoped mixed assoc: scoping');
-    ok (grep ($_->[TM->SCOPE] eq 'us',  @res), 'scoped mixed assoc: scoping');
-
-    foreach my $r (@res) {
-	ok (eq_set ([ @{$r->[TM->PLAYERS]} ],
-		    [ 'tm:play1', 'tm:play2' ]), 'scoped mixed assoc: players');
-	ok (eq_set ([ @{$r->[TM->ROLES]} ],
-		    [ 'tm:role1', 'tm:role2' ]), 'scoped mixed assoc: roles');
-    }
-}
-
-{ # assoc with nested topic
-    my $ms = _parse (q|
-aaa ( [ play1: ccc ]:  role1, play2: role2)
-|);
-#warn Dumper $ms;
-
-    my @res = $ms->match (TM->FORALL, type => 'tm:aaa');
-    ok (eq_set ([ map { @{$_->[TM->PLAYERS]}  } @res ],
-		[ 'tm:play1', 'tm:play2' ]), 'assoc + embed: players');
-    ok (eq_set ([ map { @{$_->[TM->ROLES]}  } @res ],
-		[ 'tm:role1', 'tm:role2' ]), 'assoc + embed: roles');
-
-    @res = $ms->match (TM->FORALL, type => 'isa', irole => 'instance', iplayer => 'tm:play1');
-    ok (eq_set ([ map { @{$_->[TM->PLAYERS]}  } @res ],
-		[ 'tm:play1', 'tm:ccc' ]), 'assoc + embed: types');
-}
-
-# reifications
-
-{ # reified assocs
-    my $ms = _parse (q|
-aaa ( play1: role1, play2: role2) ~ xxx
-
-|);
-#warn Dumper $ms;
-    my ($a) = $ms->match (TM->FORALL, type => 'tm:aaa');
-    is ($a->[TM->LID], $ms->midlet ('tm:xxx')->[TM->ADDRESS], 'assoc reification');
-}
-
-{ # reified occurrence
-    my $ms = _parse (q|
-{aaa, bbb, "http://xxxt/" } ~ xxx
-		     |);
-#warn Dumper $ms;
-    my ($a) = $ms->match (TM->FORALL, type => 'tm:bbb');
-    is ($a->[TM->LID], $ms->midlet ('tm:xxx')->[TM->ADDRESS], 'occurrence reification');
-}
-
-{ # reified basename
-    my $ms = _parse (q|
-[ aaa = "AAA" ~ xxx ]
-		     |);
-#warn Dumper $ms;
-    my ($a) = $ms->match (TM->FORALL, type => 'name');
-    is ($a->[TM->LID], $ms->midlet ('tm:xxx')->[TM->ADDRESS], 'basename reification');
-}
-
-#== Directives ========================
-
-{ # wrong VERSION format
-    die_ok (q|
-#VERSION "123"
-|, 'not supported');
-}
-
-
-{ # wrong VERSION
-    die_ok (q|
-#VERSION "1.4"
-|, 'not supported');
-}
-
-{ # VERSION
-    my $ms = _parse (q|
-
-#VERSION "1.3"
-
-[ aaa ]
-|);
-
-ok (1, 'version supported');
-}
-
-{ # TOPICMAP
-    die_ok (q|
-#TOPICMAP ~ xxxx
-|, 'use proper');
-}
-
-
-{ # INCLUDE
-    die_ok (q|
-[aaa]
-
-#INCLUDE "xyz:abc"
-|, 'unable to load');
-
-}
-
-{ # INCLUDE
-    my $ms = _parse (q|
-[ aaa ]
-
-#INCLUDE "inline: [ bbb ]"
-
-[ ccc ]
-|);
-#    warn Dumper $ms;
-
-    ok ($ms->midlet ('tm:aaa'), 'include: topic');
-    ok ($ms->midlet ('tm:bbb'), 'include: topic');
-    ok ($ms->midlet ('tm:ccc'), 'include: topic');
-}
-
-{
-    die_ok (q|
-
-aa:uuu (bbb:play: bbb:role)
-
-|, 'unparseable');
-}
-
-{ # PREFIXES
-    my $ms = _parse (q|
-
-#PREFIX aaa @ "http://xxxx/#"
-#PREFIX bbb @ "http://yyyy/#"
-
-aaa:uuu (play: bbb:role)
-
-|);
-
-#    warn Dumper $ms;
-    
-    my @res = $ms->match (TM->FORALL, type => $ms->tids ('http://xxxx/#uuu'));
-    ok (scalar @res == 1, 'prefixed assoc name: found');
-    ok (eq_set ([ map { @{$_->[TM->PLAYERS]}  } @res ],
-		[ 'tm:play' ]), 'unprefixed player name');
-
-    my $id = $ms->tids ('http://yyyy/#role');
-    ok (eq_set ([ map { @{$_->[TM->ROLES]}  } @res ],
-		[ $id ]), 'prefixed role name');
-}
-
-die_ok (q{
-#MERGEMAP "inline: [ bbb ]" "rumsti"
-}, 'unsupported', 'invalid TM format');
-
-{ # MERGEMAP
-    my $ms = _parse (q|
-#MERGEMAP "inline: [ bbb ]" "ltm"
-
-[ aaa ]
-
-[ ccc ]
-|);
-#    warn Dumper $ms;
-
-TODO: {
-    local $TODO = "merging";
-    ok ($ms->tids ('aaa'), 'merge: topic');
-    ok ($ms->tids ('bbb'), 'merge: topic');
-    ok ($ms->tids ('ccc'), 'merge: topic');
-}
-}
-
-{ # MERGEMAP (default
-    my $ms = _parse (q|
-#MERGEMAP "inline: [ bbb ]"
-
-[ aaa ]
-
-[ ccc ]
-|);
-#    warn Dumper $ms;
-
-TODO: {
-    local $TODO = "merging (default)";
-    ok ($ms->tids ('aaa'), 'merge: topic');
-    ok ($ms->tids ('bbb'), 'merge: topic');
-    ok ($ms->tids ('ccc'), 'merge: topic');
-}
-}
-
-
-__END__
-
-
-
-__END__
-
-die_ok (q{
-format-for ([ ltm ] : standard, topic-maps )
-
-@"abssfsdf"
-
-}, 1, 'invalid encoding');
-
-$tm = new XTM (tie => new XTM::LTM ( text => q{
-  
-
-@"iso8859-1"
-
- { ltm , test , [[Ich chan Glaas sse, das tuet mir nd weeh]] }
-
-}));
-
-like ($tm->topic ('ltm')->occurrences->[0]->resource->data, qr/\x{E4}sse/, 'encoding from iso8859-1');
-
-
-
-die_ok (q{
-format-for ([ ltm ] : standard, topic-maps )
-
-xxxx
-
-{ ltm , test , "http://rumsti/" }
-}, 1, 'unknown keyword');
-
-die_ok (q{
-format-for ([ ltm ] : standard, topic-maps 
-}, 1, 'missing terminator 1');
-
-die_ok (q{
-[ ltm : format <= "The linear topic map notation" @ "http://something1/" @ "http://something2/" ]
-}, 1, 'invalid terminator 1');
-
-die_ok ('
-{ ltm , test , "http://rumsti/" '
-, 1, 'missing terminator 2');
-
-die_ok ('
-{ ltm , test , "http://rumsti/" } abc'
-, 1, 'additional nonparsable text');
-
-
-$tm = new XTM (tie => new XTM::LTM ( text => q{
-  [ ltm ]
-  { ltm , test , [[http://rumsti/
-ramsti romsti ]] }
-}));
-is (@{$tm->topics('occurrence regexps /rumsti/')}, 1, 'occurrence with topic');
-is (@{$tm->topics('occurrence regexps /romsti/')}, 1, 'occurrence with topic, multiline');
-
-#print Dumper $tm;
-
-$tm = new XTM (tie => new XTM::LTM ( text => q{
-  [ ltm ]
-  { ltm , test , "http://rumsti/" }
-}));
-is (@{$tm->topics('occurrence regexps /rumsti/')}, 1, 'occurrence with topic');
-is (@{$tm->topics()},                              2, 'occurrence with topic, 2');
-
-#print Dumper $tm;
-
-$tm = new XTM (tie => new XTM::LTM ( text => q{
-  { ltm , test ,  "http://rumsti/" }
-  { ltm , test2 , "http://ramsti/" }
-  { ltm2, test ,  "http://rumsti/" }
-}));
-is (@{$tm->topics('occurrence regexps /rumsti/')}, 2, 'occurrence wo topic');
-
-
-$tm = new XTM (tie => new XTM::LTM ( text => q{
-[ ltm : format = "The linear topic map notation" @ "http://something1/" @ "http://something2/" ]
-}));
-is (@{$tm->topics('indicates regexps /something1/')}, 1, 'subject indication1');
-is (@{$tm->topics('indicates regexps /something2/')}, 1, 'subject indication2');
-
-$tm = new XTM (tie => new XTM::LTM ( text => q{
-[ ltm : format = "The linear topic map notation" % "http://something/" ]
-}));
-is (@{$tm->topics('reifies regexps /something/')}, 1, 'subject reification');
-
-
-
-#__END__
-
-$tm = new XTM (tie => new XTM::LTM ( text => q{
-[ ltm : format = "The linear topic map notation"  ]
-}));
-is (@{$tm->topics('baseName regexps /linear/')}, 1, 'basename wo scope');
-
-$tm = new XTM (tie => new XTM::LTM ( text => q{
-[ ltm : format = "The linear topic map notation / scope1"  ]
-}));
-is (@{$tm->topics('baseName regexps /linear/')}, 1, 'basename with scope');
-
-
-#__END__
-
-
-
-# with types
-my @types = qw(format1 format2 format3);
-$tm = new XTM (tie => new XTM::LTM ( text => q{
-[ ltm : }.join (" ", @types).q{  ]
-}));
-is (@{$tm->topics()}, 4, 'topic with types');
-foreach my $t (@types) {
-  is (@{$tm->topics("is-a $t")}, 1, "finding $t");
-}
-
-
-
-__END__
-
-
-use strict;
-
-# change 'tests => 1' to 'tests => last_test_to_print';
-use Test::More qw(no_plan);
-
-use Data::Dumper;
-$Data::Dumper::Indent = 1;
-
-sub _chomp {
-    my $s = shift;
-    chomp $s;
-    return $s;
-}
-
-use TM;
-use TM::PSI;
-
-ok (1);
-
-__END__
-
-sub _parse {
-  my $text = shift;
-  my $ms = new TM (baseuri => 'tm:');
-  my $p  = new TM::AsTMa::Fact (store => $ms);
-  my $i  = $p->parse ("$text\n");
-  return $ms;
-}
-
-sub _q_players {
-    my $ms = shift;
-#    my @res = $ms->match (TM->FORALL, @_);
-#    warn "res no filter ".Dumper \@res;
-    my @res = grep ($_ !~ m|^tm:|, map { ref($_) ? $_->[0] : $_ } map { @{$_->[TM->PLAYERS]} } $ms->match (TM->FORALL, @_));
-#    warn "res ".Dumper \@res;
-    return \@res;
-}
-
-##===================================================================================
-
-#== TESTS ===========================================================================
-
-require_ok( 'TM::AsTMa::Fact' );
-
-{ # class ok
-    my $p = new TM::AsTMa::Fact;
-    ok (ref($p) eq 'TM::AsTMa::Fact', 'class ok');
-}
-
-{ #-- structural
-    my $ms = _parse ('aaa (bbb)
-
-ccc (bbb)
-');
-#warn Dumper $ms; exit;
-
-    is (scalar $ms->match_forall (type => 'isa', irole => 'class', iplayer => 'tm:bbb'), 2, 'two types for bbb');
-    ok (eq_array ([
-                   $ms->mids ('aaa', 'bbb', 'ccc')
-                   ],
-                  [
-                   'tm:aaa', 'tm:bbb', 'tm:ccc'
-                   ]), 'aaa, bbb, ccc internalized');
-}
-
-{ #-- structural
-    my $ms = _parse ('aaa (bbb)
-');
-#warn Dumper $ms;
-    is (scalar $ms->match (TM->FORALL, type => 'isa', arole => 'instance', aplayer => 'tm:aaa', 
-			                              brole => 'class',    bplayer => 'tm:bbb'), 1, 'one type for aaa');
-    ok (eq_array ([
-		   $ms->mids ('aaa', 'bbb')
-		   ],
-		  [
-		   'tm:aaa', 'tm:bbb'
-		   ]), 'aaa, bbb internalized');
-}
-
-{
-    my $ms = _parse ('aaa
-');
-#warn Dumper $ms;
-    is ($ms->mids ('aaa'), 'tm:aaa', 'aaa implicitely internalized');
-}
-
-{ # structural topic
-  my $ms = _parse (q|
-aaa is-a bbb
-bn: AAA
-oc: http://BBB
-in: blabla bla
-|);
-#warn Dumper $ms;
-  is (scalar $ms->match (TM->FORALL, type => 'isa',        irole => 'instance', iplayer => 'tm:aaa' ), 1, 'one type for aaa');
-  is (scalar $ms->match (TM->FORALL,                       irole => 'thing',    iplayer => 'tm:aaa' ), 4, 'chars for aaa');
-  is (scalar $ms->match (TM->FORALL, type => 'name',       irole => 'thing',    iplayer => 'tm:aaa' ), 1, 'basenames for aaa');
-  is (scalar $ms->match (TM->FORALL, type => 'occurrence', irole => 'thing',    iplayer => 'tm:aaa' ), 2, 'occurrences for aaa 1');
-}
-
-#-- syntactic issues ----------------------------------------------------------------
-
-my $npa = scalar keys %{$TM::infrastructure->{assertions}};
-my $npt = scalar keys %{$TM::infrastructure->{mid2iid}};
-
-{
-  my $ms = _parse (q|
-# this is AsTMa
-
-|);
-#warn Dumper $ms;
-  is (scalar $ms->match(), $npa, 'empty map 1 (assertions)');
-  is ($ms->toplets,        $npt, 'empty map 2 (toplets)');
-}
-
-{ # empty line with blanks
-  my $ms = _parse (q|
-topic1
-   
-topic2
-
-|);
-##warn Dumper $ms;
-  is (scalar $ms->toplets(), $npt+2, 'empty line contains blanks');
-}
-
-{ # empty lines with \r
-    my $ms = _parse (q|
-topic1
-topic2

-topic3


-|);
-
-    is (scalar $ms->toplets(), $npt+3, 'empty line \r contains blanks');
-}
-
-{ # using TABs as separators
-    my $ms = _parse (q|
-topic1	(	topic2	)
-	# comment
-|);
-#warn Dumper $ms;
-    is (scalar $ms->toplets, $npt+2, 'using TABs as separators');
-}
-
-{
-  my $ms = _parse (q|
-# comment1
-
-aaa (bbbbb cccc dddd)
-
-#comment2
-
-#comment4
-ccc (bbb)
-#comment3
-#comment4
-ddd (xxxx)
-#comment5
-|);
-##warn Dumper $ms;
-
-  is (scalar $ms->toplets, $npt+8, 'test comment/separation');
-  is (scalar $ms->match (TM->FORALL, type => 'isa', irole => 'instance', iplayer => 'tm:aaa' ), 3, 'types for aaa');
-  is (scalar $ms->match (TM->FORALL, type => 'isa', irole => 'instance', iplayer => 'tm:ccc' ), 1, 'type  for ccc');
-  is (scalar $ms->match (TM->FORALL, type => 'isa', irole => 'instance', iplayer => 'tm:ddd' ), 1, 'type  for ddd');
-}
-
-{ # line continuation with comments
-    my $ms = _parse (q|
-
-topic1
-# comment \
-topic2
-
-|);
-    is (scalar $ms->toplets, $npt+1, 'continuation in comment');
-}
-
-{ # line continuation with comments
-    my $ms = _parse (q|
-
-topic1
-# comment \
-
-topic2
-
-|);
-    is (scalar $ms->toplets, $npt+2, 'continuation in comment, not 1');
-}
-
-{ # line continuation with comments
-    my $ms = _parse (q|
-topic1
-# comment \ 
-topic2
-
-|);
-    is (scalar $ms->toplets, $npt+2, 'continuation in comment, not 2');
-}
-
-{ # line continuation
-  my $ms = _parse (q|
-aaa (bbbbb \
-cccc \
-dddd)
-
-|
-);
-  is (scalar $ms->toplets, $npt+4, 'line continuation');
-  is (scalar $ms->match (TM->FORALL, type => 'isa', irole => 'instance', iplayer => 'tm:aaa' ), 3, 'types for aaa');
-}
-
-{ # line continuation, not
-  my $ms = _parse (q|
-aaa
- bn: AAA
- in: a \ within the text is ok
- in: also one with a \\ followed by a blank: \\ 
- in: this is a new one \\
- in: this is not a new one
-|);
-##warn Dumper $ms;
-
-  my @res = $ms->match (TM->FORALL, type => 'occurrence', irole => 'thing', iplayer => 'tm:aaa' );
-  is (scalar @res, 3, 'ins for aaa');
-##warn Dumper \@res;
-##warn Dumper [ map { ${$_->[TM->PLAYERS]->[1]}} @res ];
-  ok (eq_set ([ 
-		map { $_->[0] }
-		map { $_->[TM->PLAYERS]->[1] } @res ],
-	      [ 'a \ within the text is ok',
-		'also one with a \ followed by a blank: \\',   # blank is gone now
-		'this is a new one  in: this is not a new one']), 'same text');
-}
-
-{ # line continuation, not \\
-  my $ms = _parse (q|
-aaa (bbbb \
-) # this is a continuation
-bn: but not this \\\\
-in: should be separate
-
-|
-);
-##warn Dumper $ms;
-  is (scalar $ms->match, $npa+3, 'line continuation, =3');
-}
-
-{ # string detection
-  my $ms = _parse (q|
-aaa
-in: AAA
-
-bbb
-in: <<<
-xxxxxxxxxxxxx
-yyyyyyyyyy
-zzzzzz
-<<<
-
-ccc
-in: <<EOM
-rumsti
-ramsti
-romsti
-<<EOM
-
-|);
-##  warn Dumper $ms;
-  is (scalar $ms->match, $npa+3, 'string detection');
-  my @res = $ms->match (TM->FORALL, type => 'occurrence', irole => 'thing', iplayer => 'tm:bbb' );
-  ok (eq_set ([ map { $_->[0] } map { $_->[TM->PLAYERS]->[1] } @res ],
-	      [ 'xxxxxxxxxxxxx
-yyyyyyyyyy
-zzzzzz',
-		]), 'same text [<<<]');
-
-  @res = $ms->match (TM->FORALL, type => 'occurrence', irole => 'thing', iplayer => 'tm:ccc' );
-  ok (eq_set ([ map { $_->[0] } map { $_->[TM->PLAYERS]->[1] } @res ],
-	      [ 'rumsti
-ramsti
-romsti',
-		]), 'same text [<<EOM]');
-}
-
-#-- line separation -----------------------------------------------
-
-{ # line separation
-  my $ms = _parse (q|
-aaa (bbb) ~ bn: AAA ~ in: rumsti
-
-ccc (ddd) ~ bn: CCC
-|);
-##  warn Dumper $ms;
-
-  is (scalar $ms->match, $npa+5, '~ separation: assertion');
-  ok (eq_set ([ map { $_->[0] } map { $_->[TM->PLAYERS]->[1] } $ms->match (TM->FORALL, type => 'name', iplayer => 'tm:aaa' ) ] ,
-	      [ 'AAA' ]), '~ separation: AAA basename');
-}
-
-{ # line no separation
-  my $ms = _parse (q|
-aaa (bbb) ~ bn: AAA ~ in: rumsti is using ~~ in: text
-|);
-##  warn Dumper $ms;
-  is (scalar $ms->match, $npa+3, '~~ no-separation: assertions');
-  ok (eq_set ([ map { $_->[0] } map { $_->[TM->PLAYERS]->[1] } $ms->match (TM->FORALL,  type => 'occurrence', iplayer => 'tm:aaa' ) ] ,
-	      [ 'rumsti is using ~ in: text' ]), 'getting back ~ text');
-}
-
-{ # inline comments
-  my $ms = _parse (q|
-aaa
-bn: AAA  # comment
-bn: AAA# no-comment
-oc: http://rumsti#no-comment
-|);
-##  warn Dumper $ms;
-
-  is (scalar $ms->match, $npa+3, 'comment + assertions');
-  ok (eq_set ([ map { $_->[0] } map { $_->[TM->PLAYERS]->[1] } $ms->match (TM->FORALL, type => 'name', iplayer => 'tm:aaa' ) ] ,
-	      [ 'AAA',
-		'AAA# no-comment' ]), 'getting back commented basename');
-  ok (eq_set ([ map { $_->[0] } map { $_->[TM->PLAYERS]->[1] } $ms->match (TM->FORALL, type => 'occurrence', iplayer => 'tm:aaa' ) ] ,
-	      [ 'http://rumsti#no-comment' ]), 'getting back commented occ');
-}
-
-#-- structural: assocs ----------------------------------------------------------
-
-{
-    my $ms = _parse (q|
-(xxx)
-role : player
-
-|);
-##warn Dumper $ms;
-
-  is (scalar $ms->match,                                                                               $npa+1, 'basic association');
-  is (scalar $ms->match (TM->FORALL,                                       iplayer => 'tm:player' ), 1, 'finding basic association 1');
-  is (scalar $ms->match (TM->FORALL, type => 'tm:xxx',                     iplayer => 'tm:player' ), 1, 'finding basic association 2');
-  is (scalar $ms->match (TM->FORALL, type => 'tm:xxx', irole => 'tm:role', iplayer => 'tm:player' ), 1, 'finding basic association 3');
-}
-
-{
-  my $ms = _parse (q|
-(xxx)
-role : p1 p2 p3
-|);
-##  warn Dumper $ms;
-
-  is (scalar $ms->match,                                                                           $npa+1, 'basic association');
-  is (scalar $ms->match (TM->FORALL,                                       iplayer => 'tm:p1' ), 1, 'finding basic association 4');
-  is (scalar $ms->match (TM->FORALL, type => 'tm:xxx',                     iplayer => 'tm:p2' ), 1, 'finding basic association 5');
-  is (scalar $ms->match (TM->FORALL, type => 'tm:xxx', irole => 'tm:role', iplayer => 'tm:p3' ), 1, 'finding basic association 6');
-}
-
-{
-  my $ms = _parse (q|
-(xxx)
-  role : aaa bbb
-
-(xxx)
-  role : aaa
-
-|);
-##  warn Dumper $ms;
-
-  is (scalar $ms->match,                                                                            $npa+2, 'basic association');
-  is (scalar $ms->match (TM->FORALL,                                       iplayer => 'tm:aaa' ), 2, 'finding basic association 7');
-  is (scalar $ms->match (TM->FORALL, type => 'tm:xxx',                     iplayer => 'tm:bbb' ), 1, 'finding basic association 8');
-}
-
-{
-  my $ms = _parse (q|
-(xxx)
-  role1 : aaa bbb
-  role2 : ccc
-
-|);
-##warn Dumper $ms;
-
-  is (scalar $ms->match, $npa+1, 'basic association');
-  is (scalar $ms->match (TM->FORALL,                                        iplayer => 'tm:aaa' ), 1, 'finding basic association 10');
-  is (scalar $ms->match (TM->FORALL, type => 'tm:xxx',                      iplayer => 'tm:ccc' ), 1, 'finding basic association 11');
-  is (scalar $ms->match (TM->FORALL, type => 'tm:xxx', irole => 'tm:role2', iplayer => 'tm:ccc' ), 1, 'finding basic association 12');
-}
-
-{
-  my $ms = _parse (q|
-(aaa) @ sss
-  role : player
-
-|);
-#warn Dumper $ms;
-
-#  ok ($ms->is_subclass ('aaa', 'association'), 'association: subclassed');
-# is (scalar $ms->match (TM->FORALL, type=> 'isa',                        iplayer => 'tm:sss'    ),   1, 'association scoped 1');
-
-  is (scalar $ms->match, $npa+2, 'association scoped');
-  is (scalar $ms->match (TM->FORALL,                                      iplayer => 'tm:player' ),   1, 'association scoped 2');
-  is (scalar $ms->match (TM->FORALL, scope => 'tm:sss',                   iplayer => 'tm:player' ),   1, 'association scoped 3');
-}
-
-#-- reification --------------------------------------
-
-{
-  my $ms = _parse (q|
-http://rumsti.com/ is-a website
-
-urn:x-rumsti:xxx is-a rumsti
-|);
-#warn Dumper $ms;
-
-  ok (eq_array ([
-		 $ms->mids ('http://rumsti.com/','urn:x-rumsti:xxx')
-		 ],
-		[
-		 'tm:uuid-0000000000', 'tm:uuid-0000000001'
-		 ]),
-		'reification: identifiers');
-  is (scalar $ms->match, $npa+2, 'external reification: association');
-  is (scalar $ms->match (TM->FORALL,                                       iplayer => 'tm:uuid-0000000001' ), 1, 'reification: finding');
-  is (scalar $ms->match (TM->FORALL,                     type => 'isa',    iplayer => 'tm:uuid-0000000000' ), 1, 'finding basic association');
-}
-
-{
-  my $ms = _parse (q|
-cpan reifies http://cpan.org/
-
-(xxx)
-aaa: cpan
-bbb: ccc
-
-|);
-#warn Dumper $ms;
-
-  is (scalar $ms->match, $npa+1,                                                                                        'reification: association');
-  is (scalar $ms->match (TM->FORALL, type => 'tm:xxx',               iplayer => $ms->mids ('http://cpan.org/') ), 1, 'reification: finding basic association');
-  is (scalar $ms->match (TM->FORALL, type => 'tm:xxx',               iplayer => 'tm:cpan' ),  1, 'reification: finding basic association');
-
-  ok (eq_set (
-	      [ $ms->match (TM->FORALL, type => 'tm:xxx',            iplayer => $ms->mids ('http://cpan.org/') ) ],
-	      [ $ms->match (TM->FORALL, type => 'tm:xxx',            iplayer => 'tm:cpan' )          ]
-	      ), 'reification: finding, same');
-}
-
-{
-  my $ms = _parse (q|
-(http://xxx)
-  http://role1 : aaa http://bbb
-  http://role2 : ccc
-|);
-#warn Dumper $ms;
-  is (scalar $ms->match, $npa+1, 'reification: association');
-  is (scalar $ms->match (TM->FORALL, type    =>   $ms->mids('http://xxx'), 
-			             roles   => [ $ms->mids ('http://role1', 'http://role2', 'http://role1') ],
-			             players => [ $ms->mids ('tm:aaa', undef, 'http://bbb') ] ), 1, 'reification: association');
-}
-
-{ # reification explicit
-  my $ms = _parse (q|
-xxx (http://www.topicmaps.org/xtm/1.0/#psi-topic)
-|);
-#warn Dumper $ms;
-  is (scalar $ms->match, $npa+1, 'reification: type');
-
-  ok ($ms->is_asserted (Assertion->new (scope   => 'us',
-					type    => 'isa',
-					roles   => [ 'class', 'instance' ],
-					players => [ 'http://www.topicmaps.org/xtm/1.0/#psi-topic', 'tm:xxx' ])), 'xxx is-a found');
-  my $m = $ms->tids ('http://www.topicmaps.org/xtm/1.0/#psi-topic');
-  ok ($ms->is_asserted (Assertion->new (scope   => 'us',
-					type    => 'isa',
-					roles   => [ 'class', 'instance' ],
-					players => [ $m, 'tm:xxx' ])), 'xxx is-a found (via mids)');
-}
-
-{
-  my $ms = _parse (q|
-(xxx) is-reified-by aaa
-  role : player
-|);
-#warn Dumper $ms;
-  my ($a) = $ms->match (TM->FORALL, type => 'tm:xxx');
-  is_deeply ([ $ms->is_reified ($a) ], [ 'tm:aaa' ], 'assoc reified: regained');
-  is ($ms->reifies ('tm:aaa'), $a,                   'assoc reified: regained 2');
-}
-
-eval {
-  my $ms = _parse (q|
-(xxx) reifies aaa
-  role : player
-|);
-}; like ($@, qr/must be a URI/i, _chomp($@));
-
-#{
-#  my $ms = _parse (q|
-#(xxx) reifies http://rumsti/
-#  role : player
-#|);
-##warn Dumper $ms;
-#
-#  my ($a) = $ms->match (TM->FORALL, type => 'tm:xxx');
-#  is ($ms->reified_by ($a->[TM->LID]), 'http://rumsti/', 'assoc reified: regained 3');
-#}
-
-eval {
-  my $ms = _parse (q|
-(xxx) is-reified-by http://aaa/
-  role : player
-|);
-}; like ($@, qr/local identifier/i, _chomp($@));
-
-#-- syntax errors -------------------------------------------------------------------
-
-eval {
-  my $ms = _parse (q|
-(xxx zzz)
-member : aaa
-|);
-}; like ($@, qr/syntax error/i, _chomp($@));
-
-eval {
-  my $ms = _parse (q|
-(xxx)
-|);
-}; like ($@, qr/syntax error/i, _chomp($@));
-
-eval {
-  my $ms = _parse (q|
-(xxx)
-role : aaa
-role2 : 
-|);
-}; like ($@, qr/syntax error/i, _chomp($@));
-
-eval {
-  my $ms = _parse (q|
-(xxx)
-
-rumsti
-
-|);
-}; like ($@, qr/syntax error/i, _chomp($@));
-
-eval {
-  my $ms = _parse (q|
-()
-role : player
-|);
-}; like ($@, qr/syntax error/i, _chomp($@));
-
-#-- autogenerating ids
-
-{
-  my $ms = _parse (q|
-* (aaa)
-
-* (aaa)
-|);
-## warn Dumper $ms;
-
-  is (scalar $ms->match, $npa+2, 'autogenerating ids');
-  is (scalar (
-              grep /tm:uuid-\d{10}/, 
-	      map {$_->[TM->PLAYERS]->[1] } $ms->match (TM->FORALL, type => 'isa', iplayer => 'tm:aaa' ) ), 2, 'generated ids ok');
-}
-
-#-- structural: toplets/characteristics -----------------------------------------
-
-#- negative tests
-
-eval {
-   my $ms = _parse (q|
-ttt
-bn:    
-|);
-warn Dumper $ms;
-}; ok ($@, "raises except on empty bn:");
-
-eval {
-   my $ms = _parse (q|
-ttt
-oc: 
-|);
-}; ok ($@, "raises except on empty oc:");
-
-eval {
-   my $ms = _parse (q|
-ttt
-in: 
-|);
-}; ok ($@, "raises except on empty in:");
-
-eval {
-   my $ms = _parse (q|
-(aaa)
-aaa :
-|);
-   fail ("raises except on empty role");
-}; ok ($@, "raises except on empty role");
-
-eval {
-   my $ms = _parse (q|
-(aaa)
-aaa:bbb
-|);
-fail ("raises except on empty role 2");
-}; ok ($@, "raises except on empty role 2");
-
-eval {
-   my $ms = _parse (q|
-(ddd)
-bbb:aaa:ccc
-|);
-fail ("raises except on empty role 3");
-}; ok ($@, "raises except on empty role 3");
-
-
-eval {
-   my $ms = _parse (q|
-aaa
-sin (ttt): urn:xxx
-|);
-fail ("raises except on subject indicator");
-}; ok ($@, "raises except on subject indicator");
-
-eval {
-   my $ms = _parse (q|
-aaa
-sin @ sss : urn:xxx
-|);
-fail ("raises except on subject indicator");
-}; ok ($@, "raises except on subject indicator");
-
-#-- positive tests -----------------------------------
-
-{
-  # testing toplets with characteristics
-  my $ms = _parse (q|
-xxx
-bn: XXX
-|);
-##warn Dumper $ms;
-
-  is (scalar $ms->match (TM->FORALL, type => 'name', roles => [ 'value', 'thing' ], players => [ undef, 'tm:xxx' ]), 1, 'basename characteristics');
-}
-
-{
-  # testing toplets with URI
-  my $ms = _parse (q|
-http://xxx
-bn: XXX
-|);
-##warn Dumper $ms;
-
-  is (scalar $ms->match (TM->FORALL, type => 'name', roles => [ 'value', 'thing' ], 
-			                             players => [ $ms->mids (undef, 'http://xxx') ]), 1, 'basename characterisistics (reification)');
-}
-
-{
-my $ms = _parse (q|
-aaa (bbbbb)
-bn: AAA
-in:         blabla  
-|);
-##warn Dumper $ms;
-
-  ok (eq_set ([ map { map { $_->[0] } $_->[TM->PLAYERS]->[1] } $ms->match (TM->FORALL, type => 'occurrence', iplayer => 'tm:aaa' ) ] ,
-	      [ 'blabla' ]), 'test blanks in resourceData 1');
-}
-
-{
-  my $ms = _parse (q|
-xxx
-bn: XXX
-oc: http://xxx.com
-ex: http://yyy.com
-|);
-##warn Dumper $ms;
-
-  ok (eq_set ([ map { $_->[0] } map { $_->[TM->PLAYERS]->[1] } $ms->match (TM->FORALL, type => 'occurrence', iplayer => 'tm:xxx' ) ] ,
-	      [ 'http://yyy.com', 'http://xxx.com' ]), 'occurrence char, value ok');
-}
-
-
-#- adding types
-
-{
-  my $ms = _parse (q|
-aaa
- bn: AAA
- bn (rumsti) : AAAT
- in: III
- in (bumsti) : IIIT
- oc: http://xxx/
- oc (ramsti) : http://xxxt/
- oc (rimsti) : http://yyy/
- bn (remsti) : http://zzz/
- in (remsti) : bla
-|);
-#warn Dumper $ms;
-#warn "occurrences of aaa ".Dumper [ $ms->match (TemplateIPlayerType->new ( type => 'tm:occurrence',   iplayer => 'tm:aaa' )) ];
-
-  ok (eq_set ([ map { $_->[0] } map { $_->[TM->PLAYERS]->[1] } 
-                grep ($_->[TM->TYPE] eq 'name', 
-                      $ms->match (TM->FORALL, type => 'name',   iplayer => 'tm:aaa' )) ] ,
-	      [ 'AAA' ]), 'basename untyped char, value ok');
-
-  ok (eq_set ([ map { $_->[0] } map { $_->[TM->PLAYERS]->[1] } $ms->match (TM->FORALL, type => 'tm:rumsti',  iplayer => 'tm:aaa' ) ] ,
-	      [ 'AAAT' ]), 'basename typed char, value ok');
-
-  ok (eq_set ([ map { $_->[0] } map { $_->[TM->PLAYERS]->[1] } $ms->match (TM->FORALL, type => 'occurrence', iplayer => 'tm:aaa' ) ] ,
-	      [ 'http://xxxt/',
-		'http://yyy/',
-		'http://zzz/', # yes, this is also now an occurrence, since remsti is that too!
-		'III',
-		'IIIT',
-		'bla',
-		'http://xxx/' ]), 'occurr typed char, value ok');
-
-  ok (eq_set ([ map { $_->[0] } map { $_->[TM->PLAYERS]->[1] } $ms->match (TM->FORALL, type => 'tm:bumsti',         iplayer => 'tm:aaa' ) ] ,
-	      [ 'IIIT' ]), 'occurr typed char, value ok');
-  ok (eq_set (_q_players ($ms, type => 'tm:ramsti',         iplayer => 'tm:aaa' ) ,
-	      [ 'http://xxxt/' ]), 'occurr typed char, value ok');
-  ok (eq_set (_q_players ($ms, type => 'tm:remsti',         iplayer => 'tm:aaa' ) ,
-	      [ 
-		'http://zzz/',
-		'bla' ]), 'occurr typed char, value ok');
-}
-
-{ # subject indication 
-    my $ms = _parse (q|
-aaa
-bn: AAA
-sin: http://AAA
-sin: http://BBB
-
-|);
-#warn Dumper $ms;
-
-    my $t = $ms->midlet ('tm:aaa');
-    ok (eq_set (
-		$t->[TM->INDICATORS],
-		[
-		 'http://AAA',
-		 'http://BBB',
-		 ]), 'indicators');
-
-    is (scalar $ms->match (TM->FORALL, type => 'name', irole => 'thing',    iplayer => $ms->mids (\ 'http://AAA') ), 1, 'names for aaa via indication');
-    is (scalar $ms->match (TM->FORALL, type => 'name', irole => 'thing',    iplayer => $ms->mids (\ 'http://BBB') ), 1, 'names for aaa via indication');
-}
-
-#-- associations with URIs
-
-{
-  my $ms = _parse (q|
-(aaa)
-aaa:bbb : ccc
-
-(ddd)
-bbb: aaa:ccc
-|);
-##  warn Dumper $ms;
-
-  ok (eq_set ([ map { $_->[TM->PLAYERS]->[0] } $ms->match (TM->FORALL, type => 'tm:aaa',         irole => $ms->mids ('aaa:bbb') ) ] ,
-	      [ 'tm:ccc' ]), 'assoc with URIs 1');
-  ok (eq_set ([ map { $_->[TM->PLAYERS]->[0] } $ms->match (TM->FORALL, type => 'tm:ddd',         irole => 'tm:bbb' ) ] ,
-	      [ $ms->mids ('aaa:ccc') ]), 'assoc with URIs 2');
-
-}
-
-#- adding scopes
-
-{
-  my $ms = _parse (q|
-aaa
- bn: AAA
- bn @ sss : AAAS
- in: III
- in @ sss : IIIS
- oc: http://xxx/
- oc @ sss : http://xxxs/
-|);
-##  warn Dumper $ms;
-
-  ok (eq_set (_q_players ($ms, type => 'name',   iplayer => 'tm:aaa' ),
-	      [ 'AAA', 'AAAS' ]), 'basename untyped, scoped, value ok');
-  ok (eq_set (_q_players ($ms, scope => 'us', type => 'name',   iplayer => 'tm:aaa' ),
-	      [ 'AAA' ]), 'basename untyped, scoped, value ok');
-  ok (eq_set (_q_players ($ms, scope => 'tm:sss', type => 'name',   iplayer => 'tm:aaa' ),
-	      [ 'AAAS' ]), 'basename untyped, scoped, value ok');
-
-  ok (eq_set (_q_players ($ms, type => 'occurrence',   iplayer => 'tm:aaa' ),
-	      [ 'III', 'IIIS', 'http://xxx/', 'http://xxxs/' ]), 'occurrences untyped, mixscoped, value ok');
-  ok (eq_set (_q_players ($ms, scope => 'tm:sss', type => 'occurrence',   iplayer => 'tm:aaa' ),
-	      [ 'IIIS', 'http://xxxs/' ]), 'occurrences untyped, scoped, value ok');
-}
-
-{ # typed and scoped characteristics
-  my $ms = _parse (q|
-aaa
- bn (ramsti): AAA
- bn @ sss (rumsti): AAAS
- in: III
- in @ sss (ramsti): IIIS
- oc: http://xxx/
- oc @ sss (ramsti): http://xxxs/
-
-xxx (yyy)
-|);
-#  warn Dumper $ms;
-
-  ok (eq_set (_q_players ($ms, type => 'tm:ramsti',   iplayer => 'tm:aaa' ),
-	      [ 'AAA', 'IIIS', 'http://xxxs/' ]), 'basename typed, mixscoped, value ok');
-  ok (eq_set (_q_players ($ms, scope => 'us', type => 'tm:ramsti',   iplayer => 'tm:aaa' ),
-	      [ 'AAA' ]), 'basename untyped, scoped, value ok');
-  ok (eq_set (_q_players ($ms, scope => 'tm:sss', type => 'tm:rumsti',   iplayer => 'tm:aaa' ),
-	      [ 'AAAS' ]), 'basename untyped, scoped, value ok');
-
-  ok (eq_set (_q_players ($ms, type => 'name',   iplayer => 'tm:aaa' ),
-	      [   'http://xxxs/',  'AAA',  'IIIS',  'AAAS' ]), 'basenames typed, mixscoped, value ok');
-  ok (eq_set (_q_players ($ms, type => 'occurrence',   iplayer => 'tm:aaa' ),
-	      [ 'http://xxxs/',  'http://xxx/', 'AAA',  'IIIS',  'III' ]), 'occurrences typed, mixscoped, value ok');
-  ok (eq_set (_q_players ($ms, kind => TM->OCC, type => 'occurrence',   iplayer => 'tm:aaa' ),
-	      [ 'http://xxx/', 'http://xxxs/', 'IIIS',  'III' ]), 'occurrences untyped, mixscoped, value ok');
-}
-
-#-- inlined
-
-{ # checking inlined subclassing
-  my $ms = _parse (q|
-aaa is-subclass-of bbb
-
-(is-subclass-of)
- superclass: ddd
- subclass: ccc
-
-eee is-subclass-of fff is-subclass-of ggg
-
-hhh subclasses iii is-subclass-of jjj
-
-|);
-##warn Dumper $ms;
-
-  is (scalar $ms->match(TM->FORALL, type => 'is-subclass-of', roles => [ 'subclass', 'superclass' ], players => [ 'tm:aaa', 'tm:bbb' ] ), 1, 'intrinsic is-subclass-of, different forms 1');
-
-  is (scalar $ms->match(TM->FORALL, type => 'is-subclass-of', roles => [ 'subclass', 'superclass' ], players => [ 'tm:ccc', 'tm:ddd' ] ), 1, 'intrinsic is-subclass-of, different forms 2');
-
-  is (scalar $ms->match(TM->FORALL, type => 'is-subclass-of', roles => [ 'subclass', 'superclass' ], players => [ 'tm:eee', 'tm:fff' ] ), 1, 'intrinsic is-subclass-of, different forms 3');
-
-  is (scalar $ms->match(TM->FORALL, type => 'is-subclass-of', roles => [ 'subclass', 'superclass' ], players => [ 'tm:eee', 'tm:ggg' ] ), 1, 'intrinsic is-subclass-of, different forms 4');
-
-  is (scalar $ms->match(TM->FORALL, type => 'is-subclass-of', roles => [ 'subclass', 'superclass' ], players => [ 'tm:hhh', 'tm:iii' ] ), 1, 'intrinsic is-subclass-of, different forms 5');
-
-  is (scalar $ms->match(TM->FORALL, type => 'is-subclass-of', roles => [ 'subclass', 'superclass' ], players => [ 'tm:hhh', 'tm:jjj' ] ), 1, 'intrinsic is-subclass-of, different forms 6');
-
-}
-
-
-{
-  my $ms = _parse (q|
-aaa
-
-bbb is-a thing
-
-bbb is-a ccc
-
-ddd (  )
-
-eee is-a bbb is-a ccc is-a ddd
-
-xxx has-a aaa
-|);
-##warn Dumper $ms;
-
-  is (scalar $ms->match(TM->FORALL, type => 'isa', roles => [ 'class', 'instance'  ], players => [ 'tm:xxx',   'tm:aaa' ] ), 1, 'explicit is-a');
-  is (scalar $ms->match(TM->FORALL, type => 'isa', roles => [ 'class', 'instance'  ], players => [ 'tm:ccc',   'tm:bbb' ] ), 1, 'explicit is-a 2');
-
-  is (scalar $ms->match(TM->FORALL, type => 'isa', roles => [ 'class', 'instance'  ], players => [ 'tm:ddd',   'tm:eee' ] ), 1, 'explicit is-a 3');
-  is (scalar $ms->match(TM->FORALL, type => 'isa', roles => [ 'class', 'instance'  ], players => [ 'tm:ccc',   'tm:eee' ] ), 1, 'explicit is-a 4');
-  is (scalar $ms->match(TM->FORALL, type => 'isa', roles => [ 'class', 'instance'  ], players => [ 'tm:bbb',   'tm:eee' ] ), 1, 'explicit is-a 5');
-}
-
-#-- templates --------------------
-
-eval {
-   my $ms = _parse (q|
-xxx bbb zzz
-
-|);
-}; ok ($@, "raises except on undefined inline assoc");
-
-{
-  my $ms = _parse (q|
-[ (bbb)
-ccc: ddd
-eee: fff  ]
-
-xxx bbb zzz
-
-uuu bbb vvv
-
-|);
-#warn Dumper $ms;
-  is (scalar $ms->match(TM->FORALL, type => 'tm:bbb', roles => [ 'tm:ccc', 'tm:eee'  ], players => [ 'tm:ddd',   'tm:fff' ] ), 1, 'template: static');
-}
-
-{
-  my $ms = _parse (q|
-[ (bbb)
-ccc: http://psi.tm.bond.edu.au/astma/1.0/#psi-left
-eee: fff  ]
-
-xxx bbb zzz
-
-[ (bbb2)
-ccc: http://psi.tm.bond.edu.au/astma/1.0/#psi-left
-eee: http://psi.tm.bond.edu.au/astma/1.0/#psi-right  ]
-
-xxx bbb2 zzz
-
-[ (bbb3)
-http://psi.tm.bond.edu.au/astma/1.0/#psi-left : ccc
-http://psi.tm.bond.edu.au/astma/1.0/#psi-right : eee  ]
-
-xxx bbb3 zzz
-
-|);
-
-#warn Dumper $ms;
-  is (scalar $ms->match(TM->FORALL, type => 'tm:bbb',  roles => [ 'tm:ccc', 'tm:eee'  ], players => [ 'tm:xxx',   'tm:fff' ] ), 1, 'template: dyn left');
-  is (scalar $ms->match(TM->FORALL, type => 'tm:bbb2', roles => [ 'tm:ccc', 'tm:eee'  ], players => [ 'tm:xxx',   'tm:zzz' ] ), 1, 'template: dyn both, players');
-  is (scalar $ms->match(TM->FORALL, type => 'tm:bbb3', roles => [ 'tm:xxx', 'tm:zzz'  ], players => [ 'tm:ccc',   'tm:eee' ] ), 1, 'template: dyn both, roles');
-}
-
-#-- scopes as dates
-
-{
-  my $ms = _parse (q|
-aaa
- bn : AAA
- bn @ 2004-01-12 : XXX
- bn @ 2004-01-12 12:23 : YYY
-|);
-#  warn Dumper $ms;
-
-  ok (eq_set (_q_players ($ms, scope => $ms->mids ('urn:x-date:2004-01-12:00:00'), type => 'name',   iplayer => 'tm:aaa' ),
-	      [ 'XXX' ]), 'date scoped 1');
-  ok (eq_set (_q_players ($ms, scope => $ms->mids ('urn:x-date:2004-01-12:12:23'), type => 'name',   iplayer => 'tm:aaa' ),
-	      [ 'YYY' ]), 'date scoped 2');
-
-}
-
-#-- directives ------------------------------------------------------------
-
-#-- encoding
-
-{ #-- default
-  my $ms = _parse (q|
-aaa
-in: Ich chan Glaas sse, das tuet mir nd weeh
-
-bbb
-in: Mohu jst sklo, neubl? mi
-
-
-|);
-
-  ok (eq_set (_q_players ($ms, type => 'occurrence',         iplayer => 'tm:aaa' ),
-	      [ 'Ich chan Glaas sse, das tuet mir nd weeh' ]), 'encoding: same text');
-
-  ok (eq_set (_q_players ($ms, type => 'occurrence',         iplayer => 'tm:bbb' ),
-	      [ 'Mohu jst sklo, neubl? mi' ]),                'encoding: same text');
-
-}
-
-{ # -- explicit
-  my $ms = _parse (q|
-%encoding iso-8859-1
-
-aaa
-in: Ich chan Glaas sse, das tuet mir nd weeh
-|);
-
-##warn Dumper $ms;
-
-  ok (eq_set (_q_players ($ms, type => 'occurrence',         iplayer => 'tm:aaa' ),
-	      [ 'Ich chan Glaas sse, das tuet mir nd weeh' ]), 'encoding: same text');
-
-
-#   ok (eq_set ([ $ms->toplets (new Toplet (characteristics => [ [ 'universal-scope',
-# 								 'xtm-psi-occurrence',
-# 								 TM::Maplet::KIND_IN,
-# 								 '\x{E4}sse' ]])) ],
-# 	       [   'aaa' ]), 'encoding: match in with umlaut');
-}
-
-{ #-- explicit different
-  my $ms = _parse (q|
-%encoding iso-8859-2
-
-aaa
-in: Ich chan Glaas sse, das tuet mir nd weeh
-
-|);
-
-  ok (eq_set (_q_players ($ms, type => 'occurrence',         iplayer => 'tm:aaa' ),
-	      [ 'Ich chan Glaas sse, das tuet mir nd weeh' ]), 'encoding: same text');
-
-}
-
-my ($tmp);
-use IO::File;
-use POSIX qw(tmpnam);
-do { $tmp = tmpnam() ;  } until IO::File->new ($tmp, O_RDWR|O_CREAT|O_EXCL);
-END { unlink ($tmp) ; }
-
-open (STDERR, ">$tmp");
-
-{
-  my $ms = _parse (q|
-aaa
-
-%cancel
-
-bbb
-|);
-
- is (scalar $ms->toplets, $npt+1, 'cancelling');
- ERRexpect ("Cancelled");
-##warn Dumper $ms;
-}
-
-{
-  my $ms = _parse (q|
-aaa
-
-%log xxx
-
-bbb
-|);
-
- is (scalar $ms->toplets, $npt+2, 'logging');
- ERRexpect ("Logging xxx");
-}
-
-{
-my $ms = _parse (q|
-
-aaa
-
-%trace 1
-
-bbb
-
-(ddd)
-eee : fff
-
-%trace 0
-
-ccc
-
-|);
-
-ERRexpect ("start tracing: level 1");
-ERRexpect ("added toplet");
-ERRexpect ("added assertion");
-ERRexpect ("start tracing: level 0");
-}
-
-sub ERRexpect {
-    my $expect = shift;
-
-    open (ERR, $tmp);
-    undef $/;  my $s = <ERR>;
-    like ($s, qr/$expect/, "STDERR: expected '$expect'");
-    close (ERR);
-}
-
-__END__
-
-
-
-__END__
-
-# testing corrupt TM
-# testing TNC
-
-my $text = '
-
-aaa (bbb)
-bn: AAA
-';
-  foreach my $i (1..100) {
-    $text .= "
-
-aaa$i (bbb)
-bn: AAA$i
-";
-  }
-
-
-$tm = new TM (tie => new TM::Driver::AsTMa (auto_complete => 0, text => $text));
-
-warn "Parse RecDescent inclusive: $Parse::RecDescent::totincl";
-warn "Parse RecDescent exclusive: $Parse::RecDescent::totexcl";
-
-#warn "instartrule: $Parse::RecDescent::namespace000001::totincl";
-warn "instartrule: $TM::Driver::AsTMa::Parser::totincl";
-
-#warn "instartrule: $TM::AsTMa::Parser::totexcl";
-warn "namespace0001 instartrule: $Parse::RecDescent::namespace000001::astma";
-warn "namespace0001 cparserincl: $Parse::RecDescent::namespace000001::cparserincl";
-
-__END__
-
-TODO: { # assoc with multiple scope
-   local $TODO = "assoc with multiple scope";
-
-   eval {
-      my $tm = new TM (tie => new TM::Driver::AsTMa (text => '
-@ aaa bbb (is-ramsti-of)
-ramsti : xxx
-rumsti : yyy;
-'));
-   };
-
-   ok (!$@);
-} 
-
-__END__
-
-##=========================================================
-
-
--- a/t/032serialize.t
+++ b/t/032serialize.t
@@ -4,6 +4,7 @@ use warnings;
 # change 'tests => 1' to 'tests => last_test_to_print';
 use Test::More qw(no_plan);
 
+use File::Temp qw(tempfile tempdir);
 use Data::Dumper;
 $Data::Dumper::Indent = 1;
 
@@ -33,27 +34,23 @@ Class::Trait->apply ('TM', qw(TM::Serial
 }
 
 # create tmp file
-my $tmp;
-use IO::File;
-use POSIX qw(tmpnam);
-do { $tmp = tmpnam().".dump" ;  } until IO::File->new ($tmp, O_RDWR|O_CREAT|O_EXCL);
+my ($fh,$tfn) = tempfile;
 
 ##warn "\n# short sleep, no worries";
 sleep 1;
 ##warn "tmp is $tmp";
 
-END { unlink <$tmp*>  || die "cannot unlink '$tmp' file, but I am finished anyway"; }
 
 {
     my $tm = new TM (baseuri => 'tm:');
-    $tm->url ('file:'.$tmp);
+    $tm->url ('file:'.$tfn);
     $tm->internalize ('ramsti');                           # add a dummy topic
     $tm->sync_out;
 
     $tm->internalize ('rumsti');                           # add a dummy topic
     ok ($tm->mids ('rumsti'), 'added topic');              # make sure it's there
 
-    utime time+1, time+1, $tmp;                            # fake that the file has changed
+    utime time+1, time+1, $tfn;                            # fake that the file has changed
     
     $tm->sync_in;                                          # load the map again
 #    warn Dumper $tm;
--- a/t/041astmafact.t
+++ b/t/041astmafact.t
@@ -3,6 +3,7 @@ use strict;
 # change 'tests => 1' to 'tests => last_test_to_print';
 use Test::More qw(no_plan);
 
+use File::Temp qw(tempfile tempdir);
 use Data::Dumper;
 $Data::Dumper::Indent = 1;
 
@@ -1091,12 +1092,7 @@ in: Ich chan Glaas sse, das tuet mir n
 
 
 {
-    my $tmp;
-    use IO::File;
-    use POSIX qw(tmpnam);
-    do { $tmp = tmpnam().".atm" ;  } until IO::File->new ($tmp, O_RDWR|O_CREAT|O_EXCL);
-
-    my $fh = IO::File->new ("> $tmp") || die "so what?";
+	my ($fh, $tmp) = tempfile();
     print $fh q|
 aaa
 
@@ -1131,11 +1127,7 @@ eee
 
 };
 
-my ($tmp);
-use IO::File;
-use POSIX qw(tmpnam);
-do { $tmp = tmpnam() ;  } until IO::File->new ($tmp, O_RDWR|O_CREAT|O_EXCL);
-END { unlink ($tmp) ; }
+my ($fh, $tmp) = tempfile();
 
 open (STDERR, ">$tmp");
 
@@ -1214,53 +1206,3 @@ sub ERRexpect {
 }
 
 
-__END__
-
-# testing corrupt TM
-# testing TNC
-
-my $text = '
-
-aaa (bbb)
-bn: AAA
-';
-  foreach my $i (1..100) {
-    $text .= "
-
-aaa$i (bbb)
-bn: AAA$i
-";
-  }
-
-
-$tm = new TM (tie => new TM::Driver::AsTMa (auto_complete => 0, text => $text));
-
-warn "Parse RecDescent inclusive: $Parse::RecDescent::totincl";
-warn "Parse RecDescent exclusive: $Parse::RecDescent::totexcl";
-
-#warn "instartrule: $Parse::RecDescent::namespace000001::totincl";
-warn "instartrule: $TM::Driver::AsTMa::Parser::totincl";
-
-#warn "instartrule: $TM::AsTMa::Parser::totexcl";
-warn "namespace0001 instartrule: $Parse::RecDescent::namespace000001::astma";
-warn "namespace0001 cparserincl: $Parse::RecDescent::namespace000001::cparserincl";
-
-__END__
-
-TODO: { # assoc with multiple scope
-   local $TODO = "assoc with multiple scope";
-
-   eval {
-      my $tm = new TM (tie => new TM::Driver::AsTMa (text => '
-@ aaa bbb (is-ramsti-of)
-ramsti : xxx
-rumsti : yyy;
-'));
-   };
-
-   ok (!$@);
-} 
-
-##=========================================================
-
-
--- a/t/045astma2fact.t
+++ b/t/045astma2fact.t
@@ -3,6 +3,7 @@ use strict;
 # change 'tests => 1' to 'tests => last_test_to_print';
 use Test::More qw(no_plan);
 
+use File::Temp qw(tempfile tempdir);
 use Data::Dumper;
 $Data::Dumper::Indent = 1;
 
@@ -1155,12 +1156,7 @@ eval { # version, not good
 }; like ($@, qr/unsupported/i, _chomp($@));
 
 {
-    my $tmp;
-    use IO::File;
-    use POSIX qw(tmpnam);
-    do { $tmp = tmpnam().".atm" ;  } until IO::File->new ($tmp, O_RDWR|O_CREAT|O_EXCL);
-
-    my $fh = IO::File->new ("> $tmp") || die "so what?";
+    my ($fh, $tfn) = tempfile();
     print $fh q|
 aaa
 
@@ -1172,7 +1168,7 @@ ccc
 
 eee
 
-%include file:$tmp
+%include file:$tfn
 
 |);
 #warn Dumper $ms;
--- a/t/051mldbm.t
+++ b/t/051mldbm.t
@@ -4,6 +4,7 @@ use warnings;
 # change 'tests => 1' to 'tests => last_test_to_print';
 use Test::More qw(no_plan);
 
+use File::Temp qw(tempfile tempdir);
 use Data::Dumper;
 $Data::Dumper::Indent = 1;
 
@@ -26,12 +27,7 @@ unless ($warn) {
 
 require_ok( 'TM::Materialized::MLDBM' );
 
-my ($tmp);
-use IO::File;
-use POSIX qw(tmpnam);
-do { $tmp = tmpnam() ;  } until IO::File->new ($tmp, O_RDWR|O_CREAT|O_EXCL);
-
-END { unlink ($tmp) || warn "cannot unlink tmp file '$tmp'"; }
+my ($fh, $tmp) = tempfile;
 
 {
     my $tm = new TM::Materialized::MLDBM (file => $tmp);
--- a/t/052mldbm2.t
+++ b/t/052mldbm2.t
@@ -4,6 +4,8 @@ use warnings;
 # change 'tests => 1' to 'tests => last_test_to_print';
 use Test::More qw(no_plan);
 
+use File::Temp qw(tempfile tempdir);
+
 use Data::Dumper;
 $Data::Dumper::Indent = 1;
 
@@ -30,15 +32,7 @@ eval {
   my $tm = new TM::ResourceAble::MLDBM ();
 }; like ($@, qr/no file/, _chomp ($@));
 
-my ($tmp);
-use IO::File;
-use POSIX qw(tmpnam);
-do { $tmp = tmpnam() ;  } until IO::File->new ($tmp, O_RDWR|O_CREAT|O_EXCL);
-
-END { unlink ($tmp) || warn "cannot unlink tmp file '$tmp'"; }
-
-unlink ($tmp) || warn "# cannot unlink $tmp file, but that is ok";
-
+my ($fh, $tmp) = tempfile;
 {
      my $tm = new TM::ResourceAble::MLDBM (file => $tmp);
     
--- a/t/056bdb.t
+++ b/t/056bdb.t
@@ -5,13 +5,11 @@ use warnings;
 use Test::More qw(no_plan);
 
 use Data::Dumper;
+use File::Temp qw(tempfile tempdir);
 
 use_ok ('TM::ResourceAble::BDB');
 
-my ($tmp);
-use IO::File;
-use POSIX qw(tmpnam);
-do { $tmp = tmpnam() ;  } until IO::File->new ($tmp, O_RDWR|O_CREAT|O_EXCL);
+my ($fh, $tmp) = tempfile;
 
 END { unlink ("${tmp}.main", "${tmp}.assertions", "${tmp}.toplets", $tmp ) || warn "cannot unlink tmp file '$tmp'"; }
 
@@ -93,5 +91,3 @@ if (DONE) {
     ok (@as == $STATEMENTS, 'found all inserted');
 }
 
-__END__
-
--- a/t/061xtmdeserialize.t
+++ b/t/061xtmdeserialize.t
@@ -2,7 +2,7 @@ use strict;
 use warnings;
 
 use Test::More qw(no_plan);
-##use Test::Deep;
+use File::Temp qw(tempfile tempdir);
 
 use TM;
 use Class::Trait;
@@ -356,15 +356,9 @@ my $npt = scalar keys %{$TM::infrastruct
 }
 
 { # mergeMap, die Kraetzn
-# create tmp file
-    my $tmp;
-    use IO::File;
-    use POSIX qw(tmpnam);
-    do { $tmp = tmpnam().".xtm" ;  } until IO::File->new ($tmp, O_RDWR|O_CREAT|O_EXCL);
+	# create tmp file
+	my ($fh, $tmp) = tempfile("/tmp/XXXXXXXXX"); # fixme .xtm
 
-##warn "tmp is $tmp";
-
-    my $fh = IO::File->new ("> $tmp") || die "so what?";
 print $fh q|<topicMap xmlns='http://www.topicmaps.org/xtm/1.0/' xml:base="tm:" xmlns:xlink='http://www.w3.org/1999/xlink' version="1.1">
   <topic id="xxx"/>
   <topic id="yyy"/>
@@ -386,9 +380,8 @@ print $fh q|<topicMap xmlns='http://www.
     ok ($ms->toplet ('tm:xxx'),    'mergeMap: found topic');
     ok ($ms->toplet ('tm:yyy'),    'mergeMap: found topic');
     ok ($ms->toplet ('tm:aaa'),    'mergeMap: found topic');
+};
 
-    unlink ($tmp) || die "cannot unlink '$tmp' file";
-}
 
 eval {
     _parse (q|
@@ -433,56 +426,3 @@ eval {
     ok (0);
 }; ok (1, scalar 'tag mismatch');
 
-__END__
-
-# TODO test for broken URIs
-
-# welcher Schwachsinnige hat sich das einfallen lassen? multiple maps in a doc, i man....
-eval {
-    _parse (q|<?xml version="1.0"?>
-<xxxx>
-<topicMap xmlns = 'http://www.topicmaps.org/xtm/1.0/' version="1.1">
-</topicMap>
-<topicMap xmlns = 'http://www.topicmaps.org/xtm/1.0/' version="1.1">
-</topicMap>
-</xxxx>
-|);
-    ok (0);
-}; like ($@, qr/sick/, $@);
-
-__END__
-
-
-{ # variant, who is actually using this crap?
-  my $ms = _parse (q|
-<topic id="aaa">
-    <baseName>
-         <baseNameString>something</baseNameString>
-         <variant>
-             <parameters><topicRef xlink:href="#param1"/></parameters>
-             <variantName>name for param1</variantName>
-             <variant>
-                <parameters><topicRef xlink:href="#param3"/></parameters>
-                <variantName>name for param3</variantName>
-             </variant>
-         </variant>
-         <variant>
-             <parameters><topicRef xlink:href="#param2"/></parameters>
-             <variantName>name for param2</variantName>
-         </variant>
-    </baseName>
-</topic>
-|);
-#warn Dumper $ms;
-
-  my ($bn) = $ms->match (TM->FORALL, type => 'tm:has-basename',        irole => 'tm:thing',    iplayer => 'tm:aaa' );
-  my $va = $ms->variants ($bn->[TM->LID]);
-
-#warn Dumper $va;
-
-  is ($va->{'tm:param1'}->{value}, 'name for param1', 'variant: value 1');
-  is ($va->{'tm:param2'}->{value}, 'name for param2', 'variant: value 2');
-  is ($va->{'tm:param1'}->{variants}->
-           {'tm:param3'}->{value}, 'name for param3', 'variant: value 3');
-}
-
--- a/t/062xtmdeserialize.t
+++ b/t/062xtmdeserialize.t
@@ -44,463 +44,3 @@ sub _chomp {
     is ($tm2->tids ('rumsti'), 'tm://rumsti', 'default namespace: topic found');
 }
 
-__END__
-
-{ # explicit namespace + prefix
-    my $content = q|<xtm:topicMap
-   xmlns:xtm="http://www.topicmaps.org/xtm/" version='2.0'
->
-  <xtm:topic id="rumsti" />
-</xtm:topicMap>
-|;
-
-    my $tm2 = new TM (baseuri=>"tm://");
-    Class::Trait->apply ($tm2, "TM::Serializable::XTM");
-    $tm2->deserialize ($content);
-#warn Dumper $tm2;
-    is ($tm2->tids ('rumsti'), 'tm://rumsti', 'prefixed namespace: xtm: topic found');
-}
-
-{ # explicit namespace + prefix
-    my $content = q|<bamsti:topicMap
-   xmlns:bamsti="http://www.topicmaps.org/xtm/" version="2.0"
->
-  <bamsti:topic id="rumsti" />
-</bamsti:topicMap>
-|;
-
-    my $tm2 = new TM (baseuri=>"tm://");
-    Class::Trait->apply ($tm2, "TM::Serializable::XTM");
-    $tm2->deserialize ($content);
-#warn Dumper $tm2;
-    is ($tm2->tids ('rumsti'), 'tm://rumsti', 'prefixed namespace: bamsti: topic found');
-}
-
-# eval {
-#     my $content = q|<xxtopicMap xmlns='http://www.topicmaps.org/xtm/' version="2.0">
-# </xxtopicMap>
-# |;
-
-#     my $tm2 = new TM (baseuri=>"tm://");
-#     Class::Trait->apply ($tm2, "TM::Serializable::XTM");
-#     $tm2->deserialize ($content);
-#     ok (0);
-# }; like ($@, qr/element/, 'topicMap missing');
-
-#-- start with actual parsing
-
-sub _parse {
-    my $xtm = shift;
-    unless ($xtm =~ /<\?/) {
-	$xtm = qq|<?xml version="1.0"?>
-<topicMap xmlns='http://www.topicmaps.org/xtm/'
-          xmlns:xlink = 'http://www.w3.org/1999/xlink'
-          version="2.0">$xtm</topicMap>
-|;
-    }
-    my $tm = new TM (baseuri => "tm:");
-    Class::Trait->apply ($tm, "TM::Serializable::XTM");
-    $tm->deserialize ($xtm);
-    return $tm;
-}
-
-#--
-
-my $npa = scalar keys %{$TM::infrastructure->{assertions}};
-my $npt = scalar keys %{$TM::infrastructure->{mid2iid}};
-
-#-- empty maps, attrs
-
-{
-    my $ms = _parse (q|<?xml version="1.0"?>
-<topicMap xmlns='http://www.topicmaps.org/xtm/' version="2.0">
-</topicMap>
-|);
-
-#warn Dumper $ms;
-
-    is (scalar $ms->match(), $npa, 'empty map 1 (assertions)');
-    is ($ms->toplets,        $npt, 'empty map 2 (toplets)');
-}
-
-{ # topic with basename
-  my $ms = _parse (q|
-<topic id="aaa">
-  <name>
-     <value>AAA</value>
-  </name>
-</topic>
-|);
-#warn Dumper $ms;
-  is (scalar $ms->match (TM->FORALL, type => 'name',        irole => 'thing',    iplayer => 'tm:aaa' ), 1, 'basenames for aaa');
-}
-
-{ # topic with typed basename
-  my $ms = _parse (q|
-<topic id="aaa">
-  <name>
-     <type><topicRef href="#bbb"/></type>
-     <value>AAA</value>
-  </name>
-</topic>
-|);
-#warn Dumper $ms;
-  is (scalar $ms->match (TM->FORALL, type => 'name',   irole => 'thing',    iplayer => 'tm:aaa' ), 1, 'basenames for aaa (via bbb)');
-  is (scalar $ms->match (TM->FORALL, type => 'tm:bbb', irole => 'thing',    iplayer => 'tm:aaa' ), 1, 'basenames for aaa (via bbb)');
-  ok ($ms->toplet ('tm:bbb'), 'found topic (implicit)');
-}
-
-{ # topic with typed, scoped basename
-  my $ms = _parse (q|
-<topic id="aaa">
-  <name>
-     <type><topicRef href="#bbb"/></type>
-     <scope><topicRef href="#sss"/></scope>
-     <value>AAA</value>
-  </name>
-</topic>
-|);
-#warn Dumper $ms;
-
-  ok ($ms->toplet ('tm:sss'), 'found topic (implicit)');
-  is (scalar $ms->match (TM->FORALL, type => 'tm:bbb',   irole => 'thing',  iplayer => 'tm:aaa' ), 1, 'scoped, typed basenames for aaa (via bbb)');
-  is (scalar $ms->match (TM->FORALL, scope => 'tm:sss' ), 1,                                          'scoped, typed basenames for aaa (via bbb)');
-}
-
-{ # topic with resourceData occurrence
-  my $ms = _parse (q|
-<topic id="aaa">
-  <occurrence>
-     <resourceData>sldfsdlf</resourceData>
-  </occurrence>
-</topic>
-|);
-#  warn Dumper $ms;
-
-  is (scalar $ms->match (TM->FORALL, type => 'name',           irole => 'thing',    iplayer => 'tm:aaa' ), 0, 'occ: no basenames for aaa');
-  is (scalar $ms->match (TM->FORALL, type => 'occurrence',     irole => 'thing',    iplayer => 'tm:aaa' ), 1, 'occ: occurrence for aaa');
-
-  my ($o) = $ms->match (TM->FORALL, type => 'occurrence',      irole => 'thing',    iplayer => 'tm:aaa' );
-  like ($o->[TM->PLAYERS]->[1]->[0], qr/sldfsdlf/, 'occ: value');
-}
-
-{ #-- XML data as string
-  my $ms = _parse (q|
-<topic id="aaa">
-    <occurrence>
-       <resourceData>
-           <x:some  xmlns:x="html">text</x:some>
-           <x:some2 xmlns:x="xhtml">text2</x:some2>
-       </resourceData>
-    </occurrence>
-</topic>
-|);
-
-#warn Dumper $ms;
-  my ($o) = $ms->match (TM->FORALL, type => 'occurrence',    irole => 'thing',    iplayer => 'tm:aaa' );
-  is ($o->[TM->PLAYERS]->[1]->[1], TM::Literal->STRING, 'occ: XML as string');
-  like ($o->[TM->PLAYERS]->[1]->[0], qr/<x:some /,  'occ: XML value 1');
-  like ($o->[TM->PLAYERS]->[1]->[0], qr/<x:some2 /, 'occ: XML value 2');
-  like ($o->[TM->PLAYERS]->[1]->[0], qr/xmlns:x="xhtml"/, 'occ: XML value 3');
-}
-
-{ #-- XML data as XML
-  my $ms = _parse (q|
-<topic id="aaa">
-    <occurrence>
-       <resourceData datatype="http://www.w3.org/2001/XMLSchema#anyType">
-           <x:some  xmlns:x="html">text</x:some>
-           <x:some2 xmlns:x="xhtml">text2</x:some2>
-       </resourceData>
-    </occurrence>
-</topic>
-|);
-
-#warn Dumper $ms;
-  my ($o) = $ms->match (TM->FORALL, type => 'occurrence',    irole => 'thing',    iplayer => 'tm:aaa' );
-  is ($o->[TM->PLAYERS]->[1]->[1], TM::Literal->ANY, 'occ: XML as XML');
-  like ($o->[TM->PLAYERS]->[1]->[0], qr/<x:some /,  'occ: XML value 1');
-}
-
-{ #-- URI as resourceData
-  my $ms = _parse (q|
-<topic id="aaa">
-    <occurrence>
-       <resourceData datatype="http://www.w3.org/2001/XMLSchema#anyURI">http://xxx.com/</resourceData>
-    </occurrence>
-</topic>
-|);
-
-#warn Dumper $ms;
-  my ($o) = $ms->match (TM->FORALL, type => 'occurrence',    irole => 'thing',    iplayer => 'tm:aaa' );
-  is ($o->[TM->PLAYERS]->[1]->[1], TM::Literal->URI, 'occ: URI');
-  like ($o->[TM->PLAYERS]->[1]->[0], qr/http/,  'occ: URI');
-}
-
-{ #scoped, typed resourceData occurrence
-  my $ms = _parse (q|
-<topic id="aaa">
-  <occurrence>
-     <type><topicRef href="#bbb"/></type>
-     <scope><topicRef href="#sss"/></scope>
-     <resourceData>sldfsdlf</resourceData>
-  </occurrence>
-</topic>
-|);
-#warn Dumper $ms;
-
-  ok ($ms->toplet ('tm:bbb'), 'found topic (implicit)');
-  ok ($ms->toplet ('tm:sss'), 'found topic (implicit)');
-  is (scalar $ms->match (TM->FORALL, type => 'tm:bbb',      irole => 'thing',    iplayer => 'tm:aaa' ), 1, 'occ: occurrence for aaa (via bbb)');
-  is (scalar $ms->match (TM->FORALL, type => 'occurrence',  irole => 'thing',    iplayer => 'tm:aaa' ), 1, 'occ: occurrence for aaa');
-}
-
-{ # unscoped assoc
-  my $ms = _parse (q|
-<association>
-  <type><topicRef href="#atype"/></type>
-  <role>
-     <type><topicRef href="#role2"/></type>
-     <topicRef href="#player1"/>
-  </role>
-  <role>
-     <type><topicRef href="#role1"/></type>
-     <topicRef    href="#player2"/>
-  </role>
-</association>
-|);
-#warn Dumper $ms;
-
-  my @m = $ms->match (TM->FORALL, type => 'tm:atype');
-  ok (@m == 1, 'assoc: exactly one added');
-
-#warn Dumper \@m;
-  ok (eq_array (
-		$m[0]->[TM->ROLES],
-		[ 'tm:role1', 'tm:role2' ]
-		), 'assoc: roles ok');
-  ok (eq_array (
-                $m[0]->[TM->PLAYERS],
-                [ 'tm:player2', 'tm:player1' ]
-                ), 'assoc: players ok');
-  is ($m[0]->[TM->SCOPE], 'us', 'assoc: default scope');
-  ok ($ms->toplet ('tm:role1'),   'assoc: found topic (implicit)');
-  ok ($ms->toplet ('tm:role2'),   'assoc: found topic (implicit)');
-  ok ($ms->toplet ('tm:player1'), 'assoc: found topic (implicit)');
-  ok ($ms->toplet ('tm:player2'), 'assoc: found topic (implicit)');
-}
-
-{ # scoped assoc, defaults, id
-  my $ms = _parse (q|
-<association id="rumsti">
-  <type><topicRef href="#atype"/></type>
-  <scope><topicRef href="#ascope"/></scope>
-  <role>
-     <type><topicRef href="#role1"/></type>
-     <topicRef href="#player1"/>
-  </role>
-  <role>
-     <type><topicRef href="#role2"/></type>
-     <topicRef href="#player2"/>
-  </role>
-</association>
-|);
-#warn Dumper $ms;
-
-  my @m = $ms->match (TM->FORALL, type => 'tm:atype');
-  ok (@m == 1, 'assoc: exactly one added');
-
-#warn Dumper \@m;
-  ok (eq_array (
-		$m[0]->[TM->ROLES],
-		[ 'tm:role1', 'tm:role2' ]
-		), 'assoc: roles ok');
-  ok (eq_array (
-                $m[0]->[TM->PLAYERS],
-                [ 'tm:player1', 'tm:player2' ]
-                ), 'assoc: players ok');
-
-  is ($m[0]->[TM->SCOPE],  'tm:ascope', 'assoc: explicit scope');
-  @m = $ms->match (TM->FORALL, scope => 'tm:ascope');
-  ok (@m == 1, 'assoc: exactly one scoped');
-}
-
-{ # topic with subject indicator
-  my $ms = _parse (q|
-<topic id="aaa">
-   <subjectIdentifier href="http://rumsti"/>
-   <subjectIdentifier href="http://remsti"/>
-   <subjectLocator    href="http://ramsti"/>
-</topic>
-|);
-##  warn Dumper $ms;
-
-  my $t = $ms->toplet ('tm:aaa');
-  is ($t->[TM->ADDRESS], 'http://ramsti', 'subject address');
-  ok (eq_set (
-	      $t->[TM->INDICATORS],
-	      ['http://rumsti', 'http://remsti' ]), 'subject indicators');
-}
-
-{ # mergeMap, die Kraetzn
-# create tmp file
-    my $tmp;
-    use IO::File;
-    use POSIX qw(tmpnam);
-    do { $tmp = tmpnam().".xtm" ;  } until IO::File->new ($tmp, O_RDWR|O_CREAT|O_EXCL);
-
-##warn "tmp is $tmp";
-
-    my $fh = IO::File->new ("> $tmp") || die "so what?";
-print $fh q|<topicMap xmlns='http://www.topicmaps.org/xtm/1.0/' xml:base="tm:" xmlns:xlink='http://www.w3.org/1999/xlink' version="1.1">
-  <topic id="xxx"/>
-  <topic id="yyy"/>
-</topicMap>
-|;
-    $fh->close;
-
-#    warn "# sleeping for 2 secs";
-#    sleep 2;
-
-    my $ms = _parse (qq|
-<topic id="aaa"/>
-
-<mergeMap href="file:$tmp"/>
-
-|);
-#  warn Dumper $ms;
-
-    ok ($ms->toplet ('tm:aaa'),    'mergeMap: found topic');
-    ok ($ms->toplet ('tm:xxx'),    'mergeMap: found topic');
-    ok ($ms->toplet ('tm:yyy'),    'mergeMap: found topic');
-
-    unlink ($tmp) || die "cannot unlink '$tmp' file";
-}
-
-eval {
-    _parse (q|
-
-<mergeMap href="rumsti"/>
-
-|);
-    ok (0);
-}; like ($@, qr/unable to load/i, "mergeMap: "._chomp $@);
-
-eval {
-    _parse (q|
-
-<mergeMap xhref="rumsti"/>
-
-|);
-    ok (0);
-}; like ($@, qr/missing/i, "mergeMap: "._chomp $@);
-
-{ # assoc reification
-  my $ms = _parse (q|
-<association reifier="rumsti">
-   <type><topicRef href="bumsti"/></type>
-</association>
-|);
-# warn Dumper $ms;
-
-  ok ($ms->toplet ('tm:rumsti'),    'reified assoc: found reifying topic');
-  my $aid = $ms->toplet ('tm:rumsti')->[TM->ADDRESS];
-  like ($aid, qr/.{32}/, 'assoc id sane');
-  is ($ms->retrieve ($aid)->[TM->TYPE], 'tm:bumsti', 'assoc type')
-}
-
-{ # assoc reification with existing topics
-  my $ms = _parse (q|
-<topic id="rumsti"/>
-
-<association reifier="rumsti">
-   <type><topicRef href="bumsti"/></type>
-</association>
-
-<association reifier="ramsti">
-   <type><topicRef href="bumsti"/></type>
-</association>
-
-<topic id="ramsti"/>
-
-|);
-# warn Dumper $ms;
-
-  ok ($ms->toplet ('tm:rumsti'),    'reified assoc: found reifying topic');
-  ok ($ms->toplet ('tm:ramsti'),    'reified assoc: found reifying topic');
-  my $aid = $ms->toplet ('tm:rumsti')->[TM->ADDRESS];
-  like ($aid, qr/.{32}/, 'assoc id sane');
-  is ($ms->retrieve ($aid)->[TM->TYPE], 'tm:bumsti', 'assoc type');
-  $aid = $ms->toplet ('tm:ramsti')->[TM->ADDRESS];
-  like ($aid, qr/.{32}/, 'assoc id sane');
-  is ($ms->retrieve ($aid)->[TM->TYPE], 'tm:bumsti', 'assoc type');
-}
-
-{ # name, occ reification with and without existing topics
-  my $ms = _parse (q|
-<topic id="ramsti"/>
-
-<topic id="rumsti">
-   <name reifier="ramsti"><value>AAA</value></name>
-   <occurrence reifier="remsti"><resourceData>AAA</resourceData></occurrence>
-</topic>
-
-|);
-# warn Dumper $ms;
-
-  ok ($ms->toplet ('tm:rumsti'),    'reified chars: found topic');
-  ok ($ms->toplet ('tm:ramsti'),    'reified assoc: found reifying topic');
-  ok ($ms->toplet ('tm:remsti'),    'reified assoc: found reifying topic');
-
-  my $aid = $ms->toplet ('tm:ramsti')->[TM->ADDRESS];
-  like ($aid, qr/.{32}/, 'char id sane');
-  is ($ms->retrieve ($aid)->[TM->KIND], TM->NAME, 'char kind');
-  $aid = $ms->toplet ('tm:remsti')->[TM->ADDRESS];
-  like ($aid, qr/.{32}/, 'char id sane');
-  is ($ms->retrieve ($aid)->[TM->KIND], TM->OCC, 'char kind');
-}
-
-#-- errorneous situations
-
-eval {
-    _parse (q|<?xml version="1.0"?>
-<topicMaps xmlns='http://www.topicmaps.org/xtm/1.0/'/>
-|);
-}; like ($@, qr/unsupported/, _chomp $@);
-
-eval {
-    _parse (q|<?xml version="1.0"?>
-<topicMap xmlns='http://www.topicmaps.org/xtm/1.0/' version="2.2"/>
-|);
-    ok (0);
-}; like ($@, qr/version/, _chomp $@);
-
-eval {
-    _parse (q|<?xml version="1.0"?>
-<topicMap xmlns='http://wwwxxx.topicmaps.org/xtm/' version="2.0"/>
-|);
-    ok (0);
-}; like ($@, qr/namespace/, _chomp $@);
-
-eval {
-    _parse (q|
-<topic id="aaa">
-  <instanceOf><topicRef xlink:href="#type"/></instanceOf>
-  <baseName>
-     <baseNameString>Testus</baseNameString>
-  </baseName>
-</toxxxxpic>
-|);
-    ok (0);
-}; ok (1, scalar 'tag mismatch');
-
-
-
-__END__
-
-
-__END__
-
-
-
-TODO: variants
--- a/t/095tau.t
+++ b/t/095tau.t
@@ -4,6 +4,7 @@ use TM;
 use base qw(TM);
 use Class::Trait ('TM::Synchronizable' => { exclude => 'mtime' } );
 
+use File::Temp qw(tempfile tempdir);
 
 our $sync_in_called = 0;
 our $sync_out_called = 0;
@@ -43,6 +44,8 @@ package Ramsti;
 use TM::Tau::Filter;
 use base qw(TM::Tau::Filter);
 
+use File::Temp qw(tempfile tempdir);
+
 our $sync_in_called = 0;
 our $sync_out_called = 0;
 
@@ -82,16 +85,13 @@ sub _chomp {
 
 # create tmp file
 my @tmp;
-use IO::File;
-use POSIX qw(tmpnam);
-for (0..1) {
-    do { $tmp[$_] = tmpnam().".atm" ;  } until IO::File->new ($tmp[$_], O_RDWR|O_CREAT|O_EXCL);
+for (0..1)
+{
+	(my $fh, $tmp[$_]) = tempfile("/tmp/XXXXXXXXX"); # must be .atm, so hackery
+	
 }
 ##warn "tmp is $tmp";
 
-
-END { unlink (@tmp) || die "cannot unlink '@tmp' file(s), but I am finished anyway"; }
-
 sub _mk_file {
     my $file = shift;
     my $fh = IO::File->new ("> $file") || die "so what?";
@@ -203,7 +203,7 @@ use TM::Tau;
 					 ac => [ 0, 0 ], debug => 0,
 					 ud => [ 1, 0 ],
 					 ad => [ 0, 1 ] },
-	
+
  	'02 rumsti:'                => { uc => [ 1, 0 ],
 					 ac => [ 0, 0 ],
 					 ud => [ 1, 0 ],
@@ -253,7 +253,7 @@ use TM::Tau;
 #warn Dumper $tm;
 #warn "============> ". ref ($tm->left) . " <-- left -- " . ref ($tm);
 #warn "test $tau";
-#warn Dumper $tm if $tests->{$t}->{debug};      
+#warn Dumper $tm if $tests->{$t}->{debug};
 
 #    warn "synced after create ".Dumper Rumsti::synced;
 	    ok (eq_array ($tests->{$t}->{uc}, Rumsti::synced), "$tau : rumsti after creation");
@@ -291,7 +291,7 @@ use TM::Tau;
     {
 	eval "use TM::Tau::Filter::Analyze;"; # we do it to postpone the loading
 	my $tm = new TM::Tau ('null: * http://psi.tm.bond.edu.au/queries/1.0/analyze');
-    }; 
+    };
     ok (1, 'auto reg: detected');
 }
 
@@ -323,4 +323,3 @@ __END__
 
 
 __END__
-
--- a/t/096taumapsphere.t
+++ b/t/096taumapsphere.t
@@ -7,6 +7,8 @@ use TM::Tau::Filter;
 use base qw(TM::Tau::Filter);
 use Class::Trait qw(TM::MapSphere);
 
+use File::Temp qw(tempfile tempdir);
+
 sub source_in {
     my $self = shift;
 
@@ -55,6 +57,8 @@ sub new {
 use strict;
 use warnings;
 
+use File::Temp qw(tempfile tempdir);
+
 #use Class::Trait 'debug';
 
 # change 'tests => 1' to 'tests => last_test_to_print';
@@ -70,13 +74,8 @@ sub _chomp {
 
 #-- doing something with maps, preparations
 
-my ($tmp1, $tmp2);
-use IO::File;
-use POSIX qw(tmpnam);
-do { $tmp1 = tmpnam() . '.atm' ;  } until IO::File->new ($tmp1, O_RDWR|O_CREAT|O_EXCL);
-do { $tmp2 = tmpnam() ;           } until IO::File->new ($tmp2, O_RDWR|O_CREAT|O_EXCL);
-
-END { unlink ($tmp1, $tmp2) || warn "cannot unlink tmp files '$tmp1' and '$tmp2'"; }
+my ($fh, $tmp1) = tempfile("/tmp/XXXXXXX"); # fixme .atm
+my ($fh2, $tmp2) = tempfile();
 
 tmpmap ('
 aaa is-a bbb
--- a/t/100mapsphere.t
+++ b/t/100mapsphere.t
@@ -14,6 +14,7 @@ use warnings;
 # change 'tests => 1' to 'tests => last_test_to_print';
 use Test::More qw(no_plan);
 
+use File::Temp qw(tempfile tempdir);
 use Data::Dumper;
 
 my $warn = shift @ARGV;
@@ -142,430 +143,3 @@ unless ($warn) {
     ok ($tm->tids ('yyy'),                               'child yyy still alive');
 }
 
-__END__
-
-
-
-
-{
-    my $ms = new TM::MapSphere;
-
-    use TM::Materialized::AsTMa;
-    my $tm = new TM::Materialized::AsTMa (inline => 'xxx (yyy)
-');
-    $tm->sync_in;
-    $ms->mount ('/' => $tm);
-#warn Dumper $ms;
-    ok ($ms->mids ('xxx'),                              'background map, xxx');
-    ok ($ms->mids ('yyy'),                              'background map, yyy');
-}
-
-{
-    my $ms = new TM::MapSphere; #-- use map as map sphere
-
-#-- root first
-    $ms->mount ('/' => new TM);
-
-#-- one map
-    use TM::Materialized::AsTMa;
-    my $tm1 = new TM::Materialized::AsTMa (inline => 'xxx (yyy)
-');
-    $ms->mount ('/rumsti/' => $tm1);
-
-    ok ($ms->mids ('rumsti'),                            'mounted map, midlet');
-
-    is ($ms->midlet ($tms->mids('rumsti'))->[TM->ADDRESS], 
-	'tm://nirvana/',                                 'mounted midlet, address');
-    ok (eq_array ($ms->midlet ($ms->mids('rumsti'))->[TM->INDICATORS], 
-		  [
-		   'inline:xxx (yyy)
-'		   
-		   ]),                                   'mounted midlet, indicators');
-    ok (eq_set ([ $ms->instances  ('topicmap') ],
-		[ 'tm://nirvana/rumsti' ]),              'mounted midlet, found as map instance');
-    ok (eq_set ([ $ms->instances  ($ms->mids (\ 'http://psi.tm.bond.edu.au/pxtm/1.0/#psi-topicmap')) ],
-		[ 'tm://nirvana/rumsti' ]),              'mounted midlet, found as map instance');
-
-#-- second map
-    my $tm2 = new TM;
-    $ms->mount ('/ramsti/' => $tm2);
-
-    ok ($ms->is_mounted ('/ramsti/'),                     'one map mounted');
-
-    ok (eq_set ([ $ms->instances  ('topicmap') ],
-		[ 
-		  'tm://nirvana/rumsti',
-		  'tm://nirvana/ramsti'
-		  ]),                                    'mounted toplets, found as map instances');
-
-    $ms->umount ('/rumsti/');
-    ok (eq_set ([ $ms->instances  ('topicmap') ],
-		[ 'tm://nirvana/ramsti' ]),              'mounted midlet, found as map instance');
-}
-
-{
-    my $ms = new TM::MapSphere;
-
-    $ms->mount ('/'     => new TM);
-    $ms->mount ('/xxx/' => new TM);
-    eval {
-	$ms->mount ('/xxx/yyy/zzz' => new TM);
-    }; like ($@, qr/does not yet exist/,                 'deep: missing mount point error');
-
-    $ms->mount ('/xxx/yyy/' => new TM);
-    $ms->mount ('/xxx/yyy/zzz/' => new TM);
-
-    foreach my $p (qw( / /xxx/ /xxx/yyy/ /xxx/yyy/zzz/)) {
-	ok (ref ($ms->is_mounted ($p)) eq 'TM',  "mounting: mount point $p verified");
-    }
-
-    $ms->umount ('/xxx/yyy/');
-    foreach my $p (qw( / /xxx/ )) {
-	ok (ref ($ms->is_mounted ($p)) eq 'TM',  "unmounting: mount point $p verified");
-    }
-}
-
-
-use IO::File;
-use POSIX qw(tmpnam);
-
-my ($tmp);
-do { $tmp = tmpnam() ;  } until IO::File->new ($tmp, O_RDWR|O_CREAT|O_EXCL);
-END { unlink ($tmp) ; unlink ($tmp.".lock") ; }
-
-{
-    { # part I: writing something into the top
-	my $ms = new TM::MapSphere;
-	
-	use TM::Materialized::MLDBM;
-	$ms->mount ('/'     => new TM::Materialized::MLDBM (file => $tmp));
-	use TM::Materialized::AsTMa;
-	$ms->mount ('/xxx/' => new TM::Materialized::AsTMa (inline => "aaa (bbb)\n\n"));
-	
-	$ms->is_mounted ('/')->sync_out;
-
-    }
-    { # part II: getting it out again
-	my $ms = new TM::MapSphere;
-
-        use TM::Materialized::MLDBM;
-        $ms->mount ('/'     => new TM::Materialized::MLDBM (file => $tmp));
-	$ms->is_mounted ('/')->sync_in;
-#warn Dumper $ms->is_mounted ('/');
-
-	ok (eq_set ([ $ms->instances  ('topicmap') ],
-		    [ 'tm://nirvana/xxx' ]),              'regained map instance');
-
-	ok (!$ms->is_mounted ('/xxx/'),                   'no recursive automount');
-    }
-    { # part III: let MapSphere do the sync
-	my $ms = new TM::MapSphere;
-	use TM::Materialized::MLDBM;
-	$ms->mount   ('/'     => new TM::Materialized::MLDBM (file => $tmp));
-	$ms->sync_in ('/');
-
-	ok (eq_set ([ $ms->instances  ('xxxxxxtopicmap') ],
-		    [ 'tm://nirvana/xxx' ]),              'regained map instance');
-
-	my $child = $ms->is_mounted ('/xxx/');
-	ok ($child->mids ('aaa'),                         'child map, midlet');
-	ok ($child->mids ('bbb'),                         'child map, midlet');
-    }
-}
-
-
-__END__
-
-
-
-{ # try to use automatic selection
-   my $ms = new TM::MapSphere (BaseURL => 'file:/tmp/');
-   is (ref($ms), 'TM::MapSphere::MLDBM', 'selected MLDBM version');
-   is ($ms->{FILEBASE}, '/tmp/', 'correct filebase');
-
-   eval {
-       my $ms2 = new TM::MapSphere (BaseURL => 'tm://something/');
-       is (ref ($ms2), 'TM::MapSphere::Client', 'selected Client version');
-   }; if ($@) {
-       like ($@, qr/Can\'t locate/, 'exception ok, client driver not found');
-   }
-
-   $ms = new TM::MapSphere; # nothing here => should be memory
-   is (ref($ms), 'TM::MapSphere::Memory', 'selected memory version');
-
-   eval {
-       $ms = new TM::MapSphere (BaseURL => 'rumsti:xxx');
-   }; like ($@, qr/unknown/, 'exception ok, driver not existing');
-}
-
-require_ok ('TM::MapSphere::MLDBM');
-{
-    my $ms = new TM::MapSphere::MLDBM (FileBase => '/tmp/');
-    is (ref ($ms), 'TM::MapSphere::MLDBM', 'class ok');
-    is ($ms->{FILEBASE}, '/tmp/', 'filebase ok');
-    is ($ms->{METANAME}, 'meta',  'metaname ok');
-}
-
-require_ok ('TM::MapSphere::Memory');
-
-require_ok ('TM::MapSphere::Dispatch');
-
-{
-    my $md = new TM::MapSphere::Dispatch ('/' => new TM::MapSphere (BaseURL => 'file:/tmp/'));
-    ok ($md->isa ('TM::MapSphere::Dispatch') &&
-	$md->isa ('TM::MapSphere'), 'dispatch: class ok');
-    ok ($md->{mapspheres}->{'/'}->isa ('TM::MapSphere::MLDBM') &&
-	keys %{$md->{mapspheres}} == 1, 'single sphere ok');
-}
-
-{ # test internal _find_longest_match
-    my @ps = ('/', '/xxx/', '/yyy/xxx/', '/xxx/yyy/zzz/');
-    is (TM::MapSphere::Dispatch::_find_longest_match ('/xxx/yyy/',         @ps), '/xxx/',         'longest match 1');
-    is (TM::MapSphere::Dispatch::_find_longest_match ('/xxx/yyyz/',        @ps), '/xxx/',         'longest match 2');
-    is (TM::MapSphere::Dispatch::_find_longest_match ('/xx/',              @ps), '/',             'longest match 3');
-    is (TM::MapSphere::Dispatch::_find_longest_match ('/',                 @ps), '/',             'longest match 4');
-    is (TM::MapSphere::Dispatch::_find_longest_match ('/xxx/yyy/zzz/aaa/', @ps), '/xxx/yyy/zzz/', 'longest match 5');
-    eval {
-	TM::MapSphere::Dispatch::_find_longest_match ('xxxx', @ps);
-    }; like ($@, qr/no matching/, 'no path found');
-}
-
-{ # testing Mat::MapSpere a bit
-    use TM::Materialized::MapSphere;
-    eval {
-	my $tm = new TM::Materialized::MapSphere (ms => []);
-    }; ok ($@, 'faulty mapsphere');
-    my $ms = new TM::MapSphere;
-    eval {
-	my $tm = new TM::Materialized::MapSphere (ms => $ms, url => 'rumsti');
-    }; ok ($@, 'faulty URL');
-    eval {
-	my $tm = new TM::Materialized::MapSphere (ms => $ms, url => 'tm:/rumsti');
-    }; ok ($@, 'faulty URL');
-
-    my $tm = new TM::Materialized::MapSphere (ms => $ms, url => 'tm:/rumsti/');
-    ok ($tm->isa ('TM'), 'proxy class');
-}
-
-{
-    mkdir '/tmp/.ms1';
-    mkdir '/tmp/.ms2';
-
-    my $ms1 = new TM::MapSphere (BaseURL => 'file:/tmp/.ms1/');
-    my $ms2 = new TM::MapSphere (BaseURL => 'file:/tmp/.ms2/');
-    my $ms3 = new TM::MapSphere::Memory;
-    my $md = new TM::MapSphere::Dispatch ('/'     => $ms1,
-					  '/xxx/' => $ms2,
-					  '/yyy/' => $ms3);
-    use TM::Materialized::AsTMa;
-    my $tm = new TM::Materialized::AsTMa (inline => 'xxx (yyy)
-');
-    $md->tao ('/rumsti/', $tm);
-
-    ok ($ms1->tao ('/rumsti/'),    'map /rumsti/ must be in /');
-    eval {
-       $ms2->tao ('/rumsti/');
-    }; like ($@, qr/unknown map/,  'map /rumsti/ not in /xxx/');
-
-#    $md->clear;
-#    ok (!$ms1->meta ('/rumsti/'),  'no rumsti in meta');
-#    ok (!$ms2->meta ('/rumsti/'),  'no rumsti in meta');
-
-    $md->tao ('/xxx/ramsti/', $tm);
-    ok ($ms2->tao ('/ramsti/'), '/xxx/ramsti/: found /ramsti/ again');
-
-    $md->tao ('/yyy/romsti/', $tm);
-    ok ($ms3->tao ('/romsti/'), '/yyy/ramsti/: found /romsti/ again');
-
-
-    $md->untao ('/yyy/romsti/');
-    eval {
-	$md->tao ('/yyy/romsti/');
-    }; like ($@, qr/unknown/, 'romsti is gone');
-
-    $md->untao ('/xxx/ramsti/');
-    ok (-r '/tmp/.ms2/%2Framsti%2F', 'ramsti file itself here');
-    eval {
-	$md->tao ('/xxx/ramsti/');
-    }; like ($@, qr/unknown/, 'ramsti is gone');
-
-    unlink </tmp/.ms1/*>;
-    unlink </tmp/.ms2/*>;
-    rmdir  '/tmp/.ms1';
-    rmdir  '/tmp/.ms2';
-}
-
-
-LOOP:
-    foreach my $ms (
-                    new TM::MapSphere::Memory, 
-#		    new TM::MapSphere::MLDBM    (FileBase => 'file:/tmp/'),
-#		    new TM::MapSphere::Dispatch ('/'      => new TM::MapSphere::Memory)
-                    ) {
-	my $c = ref ($ms);
-	ok ($ms->isa ('TM::MapSphere'), "$c: class ok");
-	
-	{ # store a normal map there
-	    use TM::Materialized::AsTMa;
-	    my $tm = new TM::Materialized::AsTMa (inline => 'xxx (yyy)
-');
-	    my $t1 = Time::HiRes::time;
-	    $ms->tao ('/rumsti/', $tm);
-	    my $t2 = Time::HiRes::time;
-	    
-	    my $mm = $ms->meta ('/rumsti/');
-
-##warn Dumper $mm;
-	    ok ($t1 <= $mm->{created}  && $mm->{created}  <= $t2,               "$c: creation date ok");
-	    ok ($t1 <= $mm->{modified} && $mm->{modified} <= $t2,               "$c: modified date ok");
-	    
-	    my %l = $ms->locations;
-	    ok (eq_set ([keys   %l], [ '/rumsti/' ]),                           "$c: locations");
-	    ok (eq_set ([values %l], [ 'TM::Materialized::AsTMa' ]) ||
-		eq_set ([values %l], [ undef ]),                                "$c: locations");
-	    
-	    my $tm2 = $ms->tao ('/rumsti/');
-	    ok ($tm2->isa ('TM::Materialized::AsTMa'),                          "$c: found /rumsti/ again");
-	    ok ($tm2->{url} eq 'inline:xxx (yyy)
-',                                                                              "$c: maps stored and retrieved");
-
-	    eval {
-		my $t = $ms->path ('/rumsti/yyy');                               # map not synced in, so it can't have it
-		ok (0,                                                          "$c: toplet should not be there");
-	    }; like ($@, qr/empty/,                                             "$c: got no toplet");
-
-	    {
-		# I probably should not refer to internals, here, but for testing it's ok?
-		my $store = $ms->tao ('/rumsti/');
-		ok ($store,                                                         "$c: store defined");
-		my $nr = scalar keys %{$store->{assertions}};
-		
-		$ms->sync_in ('/rumsti/');                                          # this should propagate to the store
-		
-		$store = $ms->tao ('/rumsti/');
-		ok ($nr < scalar keys %{$store->{assertions}},                      "$c: mapsphere sync increased assertions");
-	    }
-
-	    my $t = $ms->path ('/rumsti/yyy');                                  # now it should work
-#warn "toplet rturned ".Dumper $t;
-	    ok (ref ($t) eq 'Toplet',                                           "$c: got toplet");
-
-	    # adding a second one, with meta data
-	    $ms->tao ('/rumsti/ramsti/', $tm, { xxx => 'yyy' });
-
-	    my %l2 = $ms->locations;
-	    ok (eq_set ([keys %l2], [ '/rumsti/', '/rumsti/ramsti/' ]),         "$c: locations 2");
-
-	    $mm = $ms->meta ('/rumsti/ramsti/');
-	    ok ($mm->{xxx} eq 'yyy',                                            "$c: additional meta data (via tao)");
-	    $ms->meta ('/rumsti/ramsti/', { aaa => 'bbb' });
-	    $mm = $ms->meta ('/rumsti/ramsti/');
-	    ok ($mm->{aaa} eq 'bbb',                                            "$c: additional meta data (via meta)");
-
-	    $ms->untao ('/rumsti/');
-	    ok ($ms->tao ('/rumsti/ramsti/'),                                   "$c: existing map found");
-	    eval {
-		$ms->tao ('/rumsti/');
-	    }; like ($@, qr/unknown/,                                           "$c: deleted map not found");
-
-	    {
-		use TM::Materialized::AsTMa;
-		my $tm    = new TM::Materialized::AsTMa (inline => 'aaa (bbb)
-');
-		$ms->tao  ('/ramsti/', $tm);
-		$ms->meta ('/ramsti/', { sync_in => 1 });
-		my $t = $ms->path ('/ramsti/aaa');
-#warn "toplet returned ".Dumper $t;
-		ok ($t->[TM->LID] eq 'tm://nirvana/aaa' &&
-		    eq_array ( [ map { ref ($_) } @{$t->[TM->CHARS]} ],
-			       [  ]),                                           "$c: ramsti path fetch");
-
-	    }
-	}
-
-#	    next LOOP;
-
-#    { # TODO check non-map objects
-#    }
-
-	{ # check T::M::MapSphere
-	    use TM::Materialized::AsTMa;
-	    my $tm    = new TM::Materialized::AsTMa (inline => 'aaa (bbb)
-');
-	    $ms->tao ('/remsti/', $tm);
-
-	    use TM::Materialized::MapSphere;
-	    my $vtm   = new TM::Materialized::MapSphere (ms  => $ms,
-							 url => 'tm:/remsti/');
-
-	    { # bad boy again, looking at internals
-		my $store = $ms->tao ('/remsti/');
-		my $nr    = scalar keys %{$store->{assertions}};
-		$vtm->sync_in;
-		ok ($vtm->is_a ('aaa', 'bbb'), 'vtm synced in');
-
-#warn "vtm ".Dumper $vtm;
-		$store = $ms->tao ('/remsti/');
-		ok ($nr < scalar keys %{$store->{assertions}}, 'TM::Materialized::MapSphere: sync increased assertions remotely');
-	    }
-
-	    ok (!$vtm->is_a ('vvv', 'uuu'), 'local change, not');
-	    my $tm3 = $ms->tao ('/remsti/');
-	    ok (!$tm3->is_a ('vvv', 'uuu'), 'remote change, not');
-
-	    $vtm->assert_maplets ([ undef, undef, 'isa', TM->KIND_ASSOC, [ 'class', 'instance' ], [ 'uuu', 'vvv' ]]);
-#warn "vtm after uuu is ".Dumper $vtm;
-
-	    ok ( $vtm->is_a ('vvv', 'uuu'), 'local change');
-	    ok (!$tm3->is_a ('vvv', 'uuu') ||                            # the reason for this bizarre is that TM::Materialized::Memory uses SHARED memory,
-                 $tm3->is_a ('vvv', 'uuu'), 'remote change, or not');    # so changes will be immediate, this may change in the future
-	    $vtm->sync_out;
-	    $tm3 = $ms->tao ('/remsti/');                                # have to refetch it
-	    ok ( $tm3->is_a ('vvv', 'uuu'), 'remote change');
-	}
-
-	{ # testing clear
-	    my %l = $ms->locations;
-	    foreach (keys %l) {
-		$ms->untao ($_);
-	    }
-	    eval {
-		$ms->tao ('/rumsti/');
-	    }; like ($@, qr/unknown map/, 'exception on non-existent map');
-	}
-
-    }
-
-unlink </tmp/meta*>;
-
-LOOP2:
-    foreach my $ms (
-		    new TM::MapSphere::Memory   (AutoList => 1),
-		    new TM::MapSphere::MLDBM    (AutoList => 1, FileBase => 'file:/tmp/'),
-		    new TM::MapSphere::Dispatch (AutoList => 1, '/'      => new TM::MapSphere::Memory),
-		    ) {
-	ok ($ms->{'AutoList'}, ref ($ms).': autolisting sticks');
-
-	use TM::Materialized::AsTMa;
-	my $tm    = new TM::Materialized::AsTMa (inline => 'aaa (bbb)
-');
-	$ms->tao ('/rumsti/',               $tm);
-	$ms->tao ('/ramsti/rimsti/',        $tm);
-	$ms->tao ('/ramsti/remsti/',        $tm);
-	$ms->tao ('/ramsti/remsti/romsti/', $tm);
-
-	my $toc = $ms->tao ('/ramsti/');                 # building table of contents
-
-	ok ($toc->isa ('TM'), 'got map');
-	ok ($toc->mids ('rimsti'), 'got entry 1');
-	ok ($toc->mids ('remsti'), 'got entry 2');
-
-	is (scalar $toc->maplets (type => 'isa', irole => 'instance', iplayer => 'rimsti'), 1, 'found map entry');
-	is (scalar $toc->maplets (type => 'isa', irole => 'instance', iplayer => 'remsti'), 2, 'found map+collection entry');
-    }
-
-__END__
-
-
-
-
--- a/t/101mapsphere.t
+++ b/t/101mapsphere.t
@@ -4,6 +4,8 @@ use TM::ResourceAble::MLDBM;
 use base qw(TM::ResourceAble::MLDBM);
 use Class::Trait qw(TM::MapSphere);
 
+use File::Temp qw(tempfile tempdir);
+
 1;
 
 
@@ -22,20 +24,16 @@ use Time::HiRes;
 
 my @tmp;
 foreach (qw(0 1 2)) {
-    use IO::File;
-    use POSIX qw(tmpnam);
-    do { $tmp[$_] = tmpnam() ;  } until IO::File->new ($tmp[$_], O_RDWR|O_CREAT|O_EXCL);
+	(my $fh, $tmp[$_]) = tempfile;
 }
 
-use File::Temp qw/ tempfile tempdir /;
 my $tmpdir = tempdir (CLEANUP => 1);
 
-END { unlink (@tmp) || warn "cannot unlink tmp files '@tmp'"; }
 
 #== TESTS =====================================================================
 
 {
-    # first basic MLDBM functionality 
+    # first basic MLDBM functionality
     { # start a sphere and add a topic
 	my $tm = new MyMapSphere2 (file => $tmpdir.'/db');
 	$tm->internalize ('aaa' => 'http://AAA/');
@@ -55,7 +53,7 @@ END { unlink (@tmp) || warn "cannot unli
 	ok ($tm->mids ('xxx'),                            'found child map topic');
 	ok (eq_set ([ $tm->instances  ('topicmap') ],
 		    [ 'tm://nirvana/xxx' ]),              'regained map instance');
-    }    
+    }
     { # is the map still there?
 	my $tm = new MyMapSphere2 (file => $tmpdir.'/db');
 	ok ($tm->is_mounted ('/xxx/'),                    'found child mounted, again');
@@ -100,4 +98,3 @@ END { unlink (@tmp) || warn "cannot unli
 	ok (!$tm->is_mounted ('/xxx/'),                    'found child unmounted after reload');
     }
 }
-
--- a/t/102mapsphere.t
+++ b/t/102mapsphere.t
@@ -16,6 +16,7 @@ use Class::Trait ('TM::MapSphere',
 
 use strict;
 use warnings;
+use File::Temp qw(tempfile tempdir);
 
 #use Class::Trait 'debug';
 
@@ -30,11 +31,9 @@ use Time::HiRes;
 my @tmp;
 
 sub _mktmps {
-    foreach (qw(0 1 2 3 4)) {
-	use IO::File;
-	use POSIX qw(tmpnam);
-	do { $tmp[$_] = tmpnam() ;  } until IO::File->new ($tmp[$_], O_RDWR|O_CREAT|O_EXCL);
-    }
+	foreach (qw(0 1 2 3 4)) {
+		my ($fh, $tfn) = tempfile;
+		$tmp[$_] = $tfn;}
 }
 
 
--- a/t/103objectable.t
+++ b/t/103objectable.t
@@ -111,362 +111,3 @@ aaa (bbb)
 }
 
 
-__END__
-
-if (DONE) {
-    my $tm = new TM;
-    use Class::Trait;
-    Class::Trait->apply ($tm, "TM::IndexAble");
-    ok ($tm->does ('TM::IndexAble'), 'index trait');
-    can_ok ($tm, 'index', 'deindex');
-};
-
-
-#$debug = 3; # pins down somewhat the tree structure
-
-if (DONE) { # lazy index, built by use, purely functional test
-    my $taxo = mk_taxo (3, 2, 3);
-#    my $taxo = mk_taxo (1, 1, 1);
-
-    my $tm = new TM;
-    implant ($tm, $taxo);
-
-    verify ($tm, $taxo, 0);  # functional test without cache
-
-    Class::Trait->apply ($tm, "TM::IndexAble");
-    my %s = $tm->index ({ axis => 'taxo' });
-#    warn Dumper \%s;
-
-    ok (eq_set ([ qw(superclass.type class.type instance.type subclass.type) ],
-                [ keys %s ]), 'axes');
-
-    map { ok ($_->{hits}     == 0, 'stat hits') 
-       && ok ($_->{requests} == 0, 'stat requests') }
-    values %s;
-
-    verify ($tm, $taxo, 0); # non-silent mode
-    verify ($tm, $taxo, 0); # non-silent mode, here everything must be already cached
-
-    %s = $tm->index;
-#warn Dumper \%s; exit;
-
-    ok ($s{'instance.type'}->{hits}     > 0, 'instance.type hits');
-    ok ($s{'instance.type'}->{requests} > 0, 'instance.type requests');
-
-    ok ($s{'subclass.type'}->{hits}     > 0, 'subclass.type hits');
-    ok ($s{'subclass.type'}->{requests} > 0, 'subclass.type requests');
-#    warn Dumper \%s;
-}
-
-sub _speedo {
-    my $tm = shift;
-    my $taxo = shift;
-
-#    diag ('speed testing for taxonomy ...');
-    my $start = Time::HiRes::time;
-    verify ($tm, $taxo, 1) for 1..5;  # speed test
-#    diag ('... done');
-    return (Time::HiRes::time - $start);
-}
-
-#-- taxo axes
-
-if (DONE) {                          # lazy index, built by use
-    my $taxo = mk_taxo (INTENSITY, 2, 2);
-
-    my $tm = new TM;
-    implant ($tm, $taxo);
-
-    my $unindexed = _speedo ($tm, $taxo);
-
-    Class::Trait->apply ($tm, "TM::IndexAble");
-    $tm->index ({ axis => 'taxo', closed => 0});  # make a cache on that axes
-
-    my $cached = _speedo ($tm, $taxo);
-    ok ($unindexed / $cached > 2, "measurable speedup (taxo) with lazy index ? ($cached < $unindexed, ".(sprintf "%.2f", $unindexed/$cached).")");
-
-#    warn Dumper $tm->index;
-
-}
-
-if (DONE) { # eager index
-    my $taxo = mk_taxo (INTENSITY, 3, 3);
-
-    my $tm = new TM;
-    implant ($tm, $taxo);
-
-    my $unindexed = _speedo ($tm, $taxo);
-
-    Class::Trait->apply ($tm, "TM::IndexAble");
-    $tm->index ({ axis => 'taxo', closed => 1});
-
-    my $indexed = _speedo ($tm, $taxo);
-    ok ($unindexed / $indexed > 2, "measurable speedup (taxo) with eager index ? ($indexed < $unindexed, ".(sprintf "%.2f", $unindexed/$indexed).")");
-}
-
-#-- char axes
-
-sub _speedo_char {
-    my $tm = shift;
-    my $taxo = shift;
-
-    my $start = Time::HiRes::time;
-    (_verify_chars ($tm, $taxo, 1) ) for 1..5;
-#    (_verify_chars ($tm, $taxo, 1)  || diag ('... run')) for 1..5;
-    return (Time::HiRes::time - $start);
-}
-
-if (DONE) { # lazy first
-    my $taxo = mk_taxo (INTENSITY, 3, 3);
-
-    my $tm = new TM;
-    implant ($tm, $taxo);
-
-    _verify_chars ($tm, $taxo, 0);
-    my $unindexed = _speedo_char ($tm, $taxo);
-
-    Class::Trait->apply ($tm, "TM::IndexAble");
-    $tm->index ({ axis => 'char', closed => 0});  # make a cache on that axes
-
-    my $cached = _speedo_char ($tm, $taxo);
-    ok ($unindexed / $cached > 2, "measurable speedup (char) with lazy index ? ($cached < $unindexed, ".(sprintf "%.2f", $unindexed/$cached).")");
-
-#    warn Dumper $tm->index;
-}
-
-if (DONE) { # eager
-    my $taxo = mk_taxo (INTENSITY, 3, 3);
-
-    my $tm = new TM;
-    implant ($tm, $taxo);
-
-    _verify_chars ($tm, $taxo, 0);
-    my $unindexed = _speedo_char ($tm, $taxo);
-
-    Class::Trait->apply ($tm, "TM::IndexAble");
-    $tm->index ({ axis => 'char', closed => 1 });  # make a cache on that axes
-
-    my $cached = _speedo_char ($tm, $taxo);
-    ok ($unindexed / $cached > 2, "measurable speedup (char) with lazy index ? ($cached < $unindexed, ".(sprintf "%.2f", $unindexed/$cached).")");
-
-#    warn Dumper $tm->index;
-}
-
-#-- reification axes
-
-sub _speedo_reif {
-    my $tm = shift;
-    my $taxo = shift;
-
-    my $start = Time::HiRes::time;
-    (_verify_reif ($tm, $taxo, 1)) for 1..5;
-#    (_verify_reif ($tm, $taxo, 1) || diag ('... run')) for 1..5;
-    return (Time::HiRes::time - $start);
-}
-
-if (DONE) {
-    my $taxo = mk_taxo (INTENSITY, 3, 3);
-    my $tm = new TM;
-    implant ($tm, $taxo);
-
-    my @as = $tm->match_forall (char => 1, type => 'occurrence');  # need to have this outside the speed test
-    _verify_reif ($tm, \@as, 0);
-    my $unindexed = _speedo_reif ($tm, \@as);
-
-    Class::Trait->apply ($tm, "TM::IndexAble");
-
-    $tm->index ({ axis => 'reify', closed => 0});  # make a cache on that axes
-    _verify_reif ($tm, \@as, 0);
-
-    my $cached = _speedo_reif ($tm, \@as);
-    ok ($unindexed / $cached > 2, "measurable speedup (reify) with lazy index ? ($cached < $unindexed, ".(sprintf "%.2f", $unindexed/$cached).")");
-}
-
-if (DONE) {
-    my $taxo = mk_taxo (INTENSITY, 3, 3);
-    my $tm = new TM;
-    implant ($tm, $taxo);
-
-    my @as = $tm->match_forall (char => 1, type => 'occurrence');  # need to have this outside the speed test
-    my $unindexed = _speedo_reif ($tm, \@as);
-
-    Class::Trait->apply ($tm, "TM::IndexAble");
-    $tm->index ({ axis => 'reify', closed => 1});
-
-    my $cached = _speedo_reif ($tm, \@as);
-    ok ($unindexed / $cached > 2, "measurable speedup (reify) with lazy index ? ($cached < $unindexed, ".(sprintf "%.2f", $unindexed/$cached).")");
-
-}
-
-
-sub _mktmp {
-    my $tmp;
-
-    use IO::File;
-    use POSIX qw(tmpnam);
-    do { $tmp = tmpnam() ;  } until IO::File->new ($tmp, O_RDWR|O_CREAT|O_EXCL);
-    return $tmp;
-}
-
-if (DONE) { # does it work together with a MLDBM backed map?
-    my $tmp = _mktmp;
-    my $taxo = mk_taxo (INTENSITY, 2, 3);
-
-    use TM::ResourceAble::MLDBM;
-    my $tm = new TM::ResourceAble::MLDBM (file => $tmp);
-#    diag ('populate map...');
-    implant ($tm, $taxo);
-#    diag ('... done');
-
-    my @as = $tm->match_forall (char => 1, type => 'occurrence');  # need to have this outside the speed test
-    my $unindexed = _speedo_reif ($tm, \@as);
-
-    Class::Trait->apply ($tm, "TM::IndexAble");
-    $tm->index ({ axis => 'reify', closed => 0});  # make a cache on that axes
-
-    _verify_reif ($tm, \@as, 0);
-#    warn Dumper $TM::IndexAble::index;exit;
-    my %s = $tm->index; # let's see what we have
-
-    my $reqs = $s{reify}->{requests};
-    is ($s{reify}->{hits}, 0, 'open => no hits');
-
-    my $cached = _speedo_reif ($tm, \@as);
-    %s = $tm->index; # let's see what we have
-    is ($s{reify}->{requests} - $s{reify}->{hits}, $reqs, 'open, but fully cached => hits');
-
-    diag ($unindexed / $cached > 2, "no measurable speedup (reify) with lazy index + MLDBM ? ($cached < $unindexed, ".(sprintf "%.2f", $unindexed/$cached).")");
-    unlink <"$tmp*">;
-}
-
-if (DONE) { # MLDBM + detached
-    my $tmp = _mktmp;
-    my $taxo = mk_taxo (INTENSITY, 2, 3);
-
-    use TM::ResourceAble::MLDBM;
-    my $tm = new TM::ResourceAble::MLDBM (file => $tmp);
-#    diag ('populate map...');
-    implant ($tm, $taxo);
-#    diag ('... done');
-
-    my @as = $tm->match_forall (char => 1, type => 'occurrence');  # need to have this outside the speed test
-    my $unindexed = _speedo_reif ($tm, \@as);
-
-    Class::Trait->apply ($tm, "TM::IndexAble");
-    $tm->index ({ axis => 'reify', closed => 0, detached => {} });
-
-    _verify_reif ($tm, \@as, 0);
-    my %s = $tm->index; # let's see what we have
-#warn " after one run ".Dumper \%s;
-
-    my $reqs = $s{reify}->{requests};
-    is ($s{reify}->{hits}, 0, 'open => no hits');
-
-    my $cached = _speedo_reif ($tm, \@as);
-    %s = $tm->index; # let's see what we have
-#warn " after second run ".Dumper \%s;
-
-    is ($s{reify}->{requests} - $s{reify}->{hits}, $reqs, 'open, but fully cached => hits');
-
-    ok ($unindexed / $cached > 2, "measurable speedup (reify) with lazy,detached index + MLDBM ? ($cached < $unindexed, ".(sprintf "%.2f", $unindexed/$cached).")");
-
-    $tm->deindex ('reify');
-    %s = $tm->index;
-    ok (! $s{reify}, 'no more reification axis index');
-
-    $tm->index ({ axis => 'reify', closed => 1, detached => {} });
-#    warn Dumper $TM::IndexAble::cachesets{ $tm->{index}->{reify} }; exit;
-       $cached = _speedo_reif ($tm, \@as);
-    ok ($unindexed / $cached > 2, "measurable speedup (reify) with eager,detached index + MLDBM ? ($cached < $unindexed, ".(sprintf "%.2f", $unindexed/$cached).")");
-
-    %s = $tm->index; # let's see what we have
-    is ($s{reify}->{requests}, $s{reify}->{hits}, 'closed & each exactly once => reqs == hits');
-
-    $tm->deindex ('reify');
-#    warn Dumper \%TM::IndexAble::cachesets;
-    ok (! keys %TM::IndexAble::cachesets, 'no more detached' );
-    %s = $tm->index;
-    ok (! $s{reify}, 'no more reification axis index');
-
-    unlink <"$tmp*">;
-}
-
-#sleep 60;
-__END__
-
-
-
-
-#-- persistent indices
-
-
-_mktmps;
-#warn Dumper \@tmp;
-
-END { map { unlink <$_*> } @tmp; };
-
-if (DONE) {
-    use BerkeleyDB ;
-    use MLDBM qw(BerkeleyDB::Hash) ;
-    use Fcntl;
-
-    my $taxo = mk_taxo (4, 3, 3);
-
-    my $unindexed;
-
-    {
-	my %cache;
-	tie %cache, 'MLDBM', -Filename => $tmp[0], -Flags    => DB_CREATE
-	    or die ( "Cannot create DBM file '$tmp[0]: $!");
-
-	my $tm   = new TM;
-	implant ($tm, $taxo);
-
-	my $idx = new TM::Index::Match ($tm, cache => \%cache);
-    
-#	warn "\n# verifying first run, should be medium fast";
-	my $start = Time::HiRes::time;
-	verify ($tm, $taxo, 1);
-	$unindexed = (Time::HiRes::time - $start);
-
-#	warn "# ====== total time =============== ".(Time::HiRes::time - $start);
-
-#	warn "# verifying second run, should be faster";
-	$start = Time::HiRes::time;
-	verify ($tm, $taxo, 1);
-	my $indexed = (Time::HiRes::time - $start);
-	ok ($indexed < $unindexed, "measurable speedup with persistent index ($indexed < $unindexed)");
-
-#	warn "# ====== total time =============== ".(Time::HiRes::time - $start);
-	
-	untie %cache;
-    }
-
-    {
-	my %cache;
-	tie %cache, 'MLDBM', -Filename => $tmp[0], -Flags => DB_CREATE
-	    or die ( "Cannot open DBM file '$tmp[0]: $!");
-
-#	warn Dumper \%cache; exit;
-
-	my $tm   = new TM;
-	implant ($tm, $taxo);
-
-	my $idx = new TM::Index::Match ($tm, cache => \%cache);
-    
-#	warn "\n# re-verifying second run, should be as fast";
-	my $start = Time::HiRes::time;
-	verify ($tm, $taxo, 1);
-	my $indexed = (Time::HiRes::time - $start);
-	ok ($indexed < $unindexed, "measurable speedup with persistent index ($indexed < $unindexed)");
-
-#	warn "# ====== total time =============== ".(Time::HiRes::time - $start);
-	
-	untie %cache;
-    }
-
-}
-
-
-__END__
-
