split stemma lib into util and object; make phylip_input microservice
[scpubgit/stemmatology.git] / TreeOfTexts / lib / TreeOfTexts / Controller / Stemmagraph.pm
index 868b3f2..d192178 100644 (file)
@@ -2,8 +2,9 @@ package TreeOfTexts::Controller::Stemmagraph;
 use Moose;
 use namespace::autoclean;
 use File::Temp;
+use JSON;
 use Text::Tradition::Collation;
-use Text::Tradition::Stemma;
+use Text::Tradition::StemmaUtil qw/ phylip_pars_input /;
 
 BEGIN { extends 'Catalyst::Controller' }
 
@@ -15,7 +16,7 @@ __PACKAGE__->config(namespace => '');
 
 =head1 NAME
 
-TreeOfTexts::Controller::Root - Root Controller for TreeOfTexts
+TreeOfTexts::Controller::Stemmagraph - Simple controller for stemma display
 
 =head1 DESCRIPTION
 
@@ -32,7 +33,6 @@ sub get_graph :Local {
        # The body is actually a File::Temp object; this is undocumented but 
        # so it seems to be.
        my $dotfile;
-       $DB::single = 1;
        my $must_unlink = 0;
        if( $c->request->params->{'dot'} ) {
            # Make a File::Temp object.
@@ -53,18 +53,22 @@ sub get_graph :Local {
     $c->forward( "View::SVG" );
 }
 
-=head2 default
+=head2 character_matrix
 
-Standard 404 error page
+Given an alignment table in JSON form, in the parameter 'alignment', returns a
+character matrix suitable for input to Phylip PARS. 
 
 =cut
 
-sub default :Path {
-    my ( $self, $c ) = @_;
-    $c->response->body( 'Page not found' );
-    $c->response->status(404);
+sub character_matrix :Local {
+       my( $self, $c ) = @_;
+       my $json = $c->request->params->{'alignment'};
+       $c->log->debug( $json );
+       my $table = from_json( $json );
+       my $matrix = phylip_pars_input( $table );
+       $c->stash->{'result'} = { 'matrix' => $matrix };
+       $c->forward( 'View::JSON' );
 }
-
 =head2 end
 
 Attempt to render a view, if needed.