From: tla Date: Mon, 28 Oct 2013 21:24:13 +0000 (+0100) Subject: ensure graph names come through for undirected graphs too (tla/stemmaweb#28) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6665a3279629a4cafac3e132d9b609310a1028f6;hp=907f66717a74634a07dd37f24fccdb5959230b27;p=scpubgit%2Fstemmatology.git ensure graph names come through for undirected graphs too (tla/stemmaweb#28) --- diff --git a/analysis/lib/Text/Tradition/Stemma.pm b/analysis/lib/Text/Tradition/Stemma.pm index 7ea5e4e..8d75edb 100644 --- a/analysis/lib/Text/Tradition/Stemma.pm +++ b/analysis/lib/Text/Tradition/Stemma.pm @@ -136,6 +136,7 @@ is( ref( $udstemma ), 'Text::Tradition::Stemma', "Created stemma from undirected is( scalar $udstemma->witnesses, 13, "Found correct number of extant witnesses" ); is( scalar $udstemma->hypotheticals, 12, "Found correct number of hypotheticals" ); ok( $udstemma->is_undirected, "Stemma was recorded as undirected" ); +is( $udstemma->identifier, "RHM stemma", "Undirected graph retained its name" ); =end testing @@ -184,18 +185,6 @@ before 'graph' => sub { } }; -after 'graph' => sub { - my $self = shift; - return unless @_; - ## HORRIBLE HACK but there is no API access to graph attributes! - my $graph_id = exists $_[0]->[4]->{'name'} ? $_[0]->[4]->{'name'} : ''; - if( $graph_id && !( $self->has_identifier && $self->identifier eq $graph_id ) ) { - $self->set_identifier( $graph_id ); - } elsif ( !$graph_id && $self->has_identifier ) { - $self->set_identifier( 'stemma' ); - } -}; - sub _graph_from_dot { my( $self, $dotfh ) = @_; my $reader = Graph::Reader::Dot->new(); @@ -218,6 +207,8 @@ sub _graph_from_dot { } elsif( !$graph ) { throw( "Failed to create graph from dot" ); } + ## HORRIBLE HACK but there is no API access to graph attributes! + my $graph_id = exists $graph->[4]->{'name'} ? $graph->[4]->{'name'} : 'stemma'; # Correct for implicit graph -> digraph quirk of reader if( $reader_err && $reader_err =~ /graph will be treated as digraph/ ) { my $udgraph = $graph->undirected_copy; @@ -227,6 +218,7 @@ sub _graph_from_dot { $graph = $udgraph; } $self->graph( $graph ); + $self->set_identifier( $graph_id ); } sub is_undirected { diff --git a/analysis/t/data/besoin_undirected.dot b/analysis/t/data/besoin_undirected.dot index 75df083..bbff89d 100644 --- a/analysis/t/data/besoin_undirected.dot +++ b/analysis/t/data/besoin_undirected.dot @@ -1,4 +1,4 @@ -graph stemma { +graph "RHM stemma" { 0 [ class=hypothetical ]; 1 [ class=hypothetical ]; 10 [ class=hypothetical ]; diff --git a/analysis/t/text_tradition_stemma.t b/analysis/t/text_tradition_stemma.t index 3650076..da22e80 100644 --- a/analysis/t/text_tradition_stemma.t +++ b/analysis/t/text_tradition_stemma.t @@ -47,6 +47,7 @@ is( ref( $udstemma ), 'Text::Tradition::Stemma', "Created stemma from undirected is( scalar $udstemma->witnesses, 13, "Found correct number of extant witnesses" ); is( scalar $udstemma->hypotheticals, 12, "Found correct number of hypotheticals" ); ok( $udstemma->is_undirected, "Stemma was recorded as undirected" ); +is( $udstemma->identifier, "RHM stemma", "Undirected graph retained its name" ); }