X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FText%2FTradition%2FDirectory.pm;h=8d9b22809b0b3707baf0b0c717151aa9b13f18b2;hb=3765080b7e9b86e2a4660d8707a10a36541661e1;hp=2fa8fc5397d412805a919422d59495dac7e92d97;hpb=0a90079324146b05a46fadc49999d423e7d93db3;p=scpubgit%2Fstemmatology.git diff --git a/lib/Text/Tradition/Directory.pm b/lib/Text/Tradition/Directory.pm index 2fa8fc5..8d9b228 100644 --- a/lib/Text/Tradition/Directory.pm +++ b/lib/Text/Tradition/Directory.pm @@ -131,6 +131,7 @@ is( ref( $nt ), 'Text::Tradition', "Made new tradition" ); like( $e->message, qr/Cannot directly delete non-Tradition object/, "Exception has correct message" ); } + $f->delete( $uuid ); ok( !$f->exists( $uuid ), "Object is deleted from DB" ); ok( !$f->exists( $sid ), "Object stemma also deleted from DB" ); @@ -141,6 +142,10 @@ is( ref( $nt ), 'Text::Tradition', "Made new tradition" ); my $g = Text::Tradition::Directory->new( 'dsn' => $dsn ); my $scope = $g->new_scope; is( scalar $g->traditionlist, 1, "Now one object in new directory index" ); + my $ntobj = $g->tradition( 'CX' ); + my @w1 = sort { $a->sigil cmp $b->sigil } $ntobj->witnesses; + my @w2 = sort{ $a->sigil cmp $b->sigil } $nt->witnesses; + is_deeply( \@w1, \@w2, "Looked up remaining tradition by name" ); } =end testing @@ -155,6 +160,8 @@ has +typemap => ( isa_entries => { "Graph" => KiokuDB::TypeMap::Entry::Naive->new, "Graph::AdjacencyMap" => KiokuDB::TypeMap::Entry::Naive->new, + "Lingua::Features::Structure" => KiokuDB::TypeMap::Entry::Naive->new, + "Lingua::Features::FeatureType" => KiokuDB::TypeMap::Entry::Naive->new, } ); }, @@ -221,7 +228,16 @@ sub save { sub tradition { my( $self, $id ) = @_; my $obj = $self->lookup( $id ); - unless( ref( $obj ) eq 'Text::Tradition' ) { + unless( $obj ) { + # Try looking up by name. + foreach my $item ( $self->traditionlist ) { + if( $item->{'name'} eq $id ) { + $obj = $self->lookup( $item->{'id'} ); + last; + } + } + } + if( $obj && ref( $obj ) ne 'Text::Tradition' ) { throw( "Retrieved object is a " . ref( $obj ) . ", not a Text::Tradition" ); } return $obj;