allow stemma dot to be file or string
[scpubgit/stemmatology.git] / lib / Text / Tradition.pm
index 8abeb6a..7995d05 100644 (file)
@@ -302,7 +302,7 @@ my $t = Text::Tradition->new(
     );
 
 my $s;
-ok( $s = $t->add_stemma( 't/data/simple.dot' ), "Added a simple stemma" );
+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" );
 
@@ -311,8 +311,18 @@ is( $t->stemma, $s, "Stemma is the right one" );
 =cut
 
 sub add_stemma {
-       my( $self, $dot ) = @_;
-       open my $stemma_fh, '<', $dot or warn "Could not open file $dot";
+       my $self = shift;
+       my %opts = @_;
+       my $stemma_fh;
+       if( $opts{'dotfile'} ) {
+               open $stemma_fh, '<', $opts{'dotfile'}
+                       or warn "Could not open file " . $opts{'dotfile'};
+       } elsif( $opts{'dot'} ) {
+               my $str = $opts{'dot'};
+               open $stemma_fh, '<', \$str;
+       }
+       # Assume utf-8
+       binmode $stemma_fh, ':utf8';
        my $stemma = Text::Tradition::Stemma->new( 
                'collation' => $self->collation,
                'dot' => $stemma_fh );