X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=TreeOfTexts%2Flib%2FTreeOfTexts%2FController%2FStemmagraph.pm;h=1d6a8e050d47d40aa9f0ba730777c0f17ab07710;hb=3837c155d39333869a93adf1e8375960ffbf3a92;hp=98c40f740272936a77646c4043798bce99243a47;hpb=5b89f7ce5b649165c48194ddaff35fbda6d52617;p=scpubgit%2Fstemmatology.git diff --git a/TreeOfTexts/lib/TreeOfTexts/Controller/Stemmagraph.pm b/TreeOfTexts/lib/TreeOfTexts/Controller/Stemmagraph.pm index 98c40f7..1d6a8e0 100644 --- a/TreeOfTexts/lib/TreeOfTexts/Controller/Stemmagraph.pm +++ b/TreeOfTexts/lib/TreeOfTexts/Controller/Stemmagraph.pm @@ -1,6 +1,7 @@ package TreeOfTexts::Controller::Stemmagraph; use Moose; use namespace::autoclean; +use File::Temp; use Text::Tradition::Collation; use Text::Tradition::Stemma; @@ -14,7 +15,7 @@ __PACKAGE__->config(namespace => ''); =head1 NAME -TreeOfTexts::Controller::Root - Root Controller for TreeOfTexts +TreeOfTexts::Controller::Stemmagraph - Simple controller for stemma display =head1 DESCRIPTION @@ -22,34 +23,35 @@ TreeOfTexts::Controller::Root - Root Controller for TreeOfTexts =head1 METHODS +=cut + sub get_graph :Local { my( $self, $c ) = @_; # If called interactively, we have params 'display', 'output', 'witnesses' # If called non-interactively, we look at headers and content. # The body is actually a File::Temp object; this is undocumented but # so it seems to be. - my $dot_fh = $c->request->body; + my $dotfile; + my $must_unlink = 0; + if( $c->request->params->{'dot'} ) { + # Make a File::Temp object. + my $tmpfile = File::Temp->new( UNLINK => 0 ); + print $tmpfile $c->request->params->{'dot'}; + $dotfile = $tmpfile->filename; + $must_unlink = 1; + } else { + $dotfile = $c->request->body; + } my $format = 'svg'; # Render the dot in the given format. my $collation = Text::Tradition::Collation->new(); - my $stemma = Text::Tradition::Stemma->new( 'collation' => $collation, 'dot' => $dot_fh ); + my $stemma = Text::Tradition::Stemma->new( 'collation' => $collation, 'dot' => $dotfile ); + unlink( $dotfile ) if $must_unlink; $c->stash->{result} = $stemma->as_svg; $c->forward( "View::SVG" ); } -=head2 default - -Standard 404 error page - -=cut - -sub default :Path { - my ( $self, $c ) = @_; - $c->response->body( 'Page not found' ); - $c->response->status(404); -} - =head2 end Attempt to render a view, if needed.