From: Tara L Andrews Date: Sat, 8 Oct 2011 14:05:31 +0000 (+0200) Subject: allow parameter passing too for stemmagraph service X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cbd0c7d9240a402f3b3db86e89f56a8c7e936a7c;p=scpubgit%2Fstemmatology.git allow parameter passing too for stemmagraph service --- diff --git a/TreeOfTexts/lib/TreeOfTexts/Controller/Stemmagraph.pm b/TreeOfTexts/lib/TreeOfTexts/Controller/Stemmagraph.pm index f2fcccc..eb9594f 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; @@ -39,12 +40,24 @@ sub get_graph :Local { # 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; + $DB::single = 1; + 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" ); }