From: Tara L Andrews Date: Thu, 2 Feb 2012 20:04:16 +0000 (+0100) Subject: allow multiple stemmas on a tradition X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2Fstemmatology.git;a=commitdiff_plain;h=e0d617e67dccc575f17f29b833b7327a1dd5d92a allow multiple stemmas on a tradition --- diff --git a/lib/Text/Tradition.pm b/lib/Text/Tradition.pm index 7995d05..8801e30 100644 --- a/lib/Text/Tradition.pm +++ b/lib/Text/Tradition.pm @@ -34,11 +34,16 @@ has 'name' => ( default => 'Tradition', ); -has 'stemma' => ( - is => 'ro', - isa => 'Text::Tradition::Stemma', - writer => '_add_stemma', - predicate => 'has_stemma', +has 'stemmata' => ( + traits => ['Array'], + isa => 'ArrayRef[Text::Tradition::Stemma]', + handles => { + all_stemmata => 'elements', + _add_stemma => 'push', + stemma => 'get', + stemma_count => 'count', + clear_stemmata => 'clear', + }, ); # Create the witness before trying to add it @@ -304,7 +309,8 @@ my $t = Text::Tradition->new( my $s; ok( $s = $t->add_stemma( dotfile => 't/data/simple.dot' ), "Added a simple stemma" ); is( ref( $s ), 'Text::Tradition::Stemma', "Got a stemma object returned" ); -is( $t->stemma, $s, "Stemma is the right one" ); +is( $t->stemma_count, 1, "Tradition claims to have a stemma" ); +is( $t->stemma(0), $s, "Tradition hands back the right stemma" ); =end testing diff --git a/lib/Text/Tradition/Directory.pm b/lib/Text/Tradition/Directory.pm index 7f97648..1685624 100644 --- a/lib/Text/Tradition/Directory.pm +++ b/lib/Text/Tradition/Directory.pm @@ -82,7 +82,7 @@ my $t = Text::Tradition->new( my $s = $t->add_stemma( dotfile => 't/data/simple.dot' ); ok( $d->save( $t ), "Updated tradition with stemma" ); is( $d->tradition( $uuid ), $t, "Correct tradition returned for id" ); - is( $d->tradition( $uuid )->stemma, $s, "...and it has the correct stemma" ); + is( $d->tradition( $uuid )->stemma(0), $s, "...and it has the correct stemma" ); try { $d->save( $s ); } catch( Text::Tradition::Error $e ) { @@ -107,7 +107,7 @@ is( ref( $nt ), 'Text::Tradition', "Made new tradition" ); is( scalar $f->tradition_ids, 2, "Directory index has both traditions" ); my $tf = $f->tradition( $uuid ); is( $tf->name, $t->name, "Retrieved the tradition from a new directory" ); - my $sid = $f->object_to_id( $tf->stemma ); + my $sid = $f->object_to_id( $tf->stemma(0) ); try { $f->tradition( $sid ); } catch( Text::Tradition::Error $e ) { diff --git a/t/text_tradition.t b/t/text_tradition.t index dd13636..b48db29 100644 --- a/t/text_tradition.t +++ b/t/text_tradition.t @@ -60,7 +60,8 @@ my $t = Text::Tradition->new( my $s; ok( $s = $t->add_stemma( dotfile => 't/data/simple.dot' ), "Added a simple stemma" ); is( ref( $s ), 'Text::Tradition::Stemma', "Got a stemma object returned" ); -is( $t->stemma, $s, "Stemma is the right one" ); +is( $t->stemma_count, 1, "Tradition claims to have a stemma" ); +is( $t->stemma(0), $s, "Tradition hands back the right stemma" ); } diff --git a/t/text_tradition_directory.t b/t/text_tradition_directory.t index e4de126..2e18c20 100644 --- a/t/text_tradition_directory.t +++ b/t/text_tradition_directory.t @@ -36,7 +36,7 @@ my $t = Text::Tradition->new( my $s = $t->add_stemma( dotfile => 't/data/simple.dot' ); ok( $d->save( $t ), "Updated tradition with stemma" ); is( $d->tradition( $uuid ), $t, "Correct tradition returned for id" ); - is( $d->tradition( $uuid )->stemma, $s, "...and it has the correct stemma" ); + is( $d->tradition( $uuid )->stemma(0), $s, "...and it has the correct stemma" ); try { $d->save( $s ); } catch( Text::Tradition::Error $e ) { @@ -61,7 +61,7 @@ is( ref( $nt ), 'Text::Tradition', "Made new tradition" ); is( scalar $f->tradition_ids, 2, "Directory index has both traditions" ); my $tf = $f->tradition( $uuid ); is( $tf->name, $t->name, "Retrieved the tradition from a new directory" ); - my $sid = $f->object_to_id( $tf->stemma ); + my $sid = $f->object_to_id( $tf->stemma(0) ); try { $f->tradition( $sid ); } catch( Text::Tradition::Error $e ) {