convert Catalyst app to use KiokuDB backend
[scpubgit/stemmatology.git] / TreeOfTexts / lib / TreeOfTexts / Controller / Stemmagraph.pm
CommitLineData
3f9bd252 1package TreeOfTexts::Controller::Stemmagraph;
2use Moose;
3use namespace::autoclean;
cbd0c7d9 4use File::Temp;
3f9bd252 5use Text::Tradition::Collation;
6use Text::Tradition::Stemma;
7
8BEGIN { extends 'Catalyst::Controller' }
9
10#
11# Sets the actions in this controller to be registered with no prefix
12# so they function identically to actions created in MyApp.pm
13#
14__PACKAGE__->config(namespace => '');
15
16=head1 NAME
17
3837c155 18TreeOfTexts::Controller::Stemmagraph - Simple controller for stemma display
3f9bd252 19
20=head1 DESCRIPTION
21
22[enter your description here]
23
24=head1 METHODS
25
a5b3c760 26=cut
27
3f9bd252 28sub get_graph :Local {
29 my( $self, $c ) = @_;
30 # If called interactively, we have params 'display', 'output', 'witnesses'
31 # If called non-interactively, we look at headers and content.
32 # The body is actually a File::Temp object; this is undocumented but
33 # so it seems to be.
cbd0c7d9 34 my $dotfile;
cbd0c7d9 35 my $must_unlink = 0;
36 if( $c->request->params->{'dot'} ) {
37 # Make a File::Temp object.
38 my $tmpfile = File::Temp->new( UNLINK => 0 );
39 print $tmpfile $c->request->params->{'dot'};
40 $dotfile = $tmpfile->filename;
41 $must_unlink = 1;
42 } else {
43 $dotfile = $c->request->body;
44 }
3f9bd252 45 my $format = 'svg';
46
47 # Render the dot in the given format.
48 my $collation = Text::Tradition::Collation->new();
cbd0c7d9 49 my $stemma = Text::Tradition::Stemma->new( 'collation' => $collation, 'dot' => $dotfile );
50 unlink( $dotfile ) if $must_unlink;
3f9bd252 51 $c->stash->{result} = $stemma->as_svg;
52 $c->forward( "View::SVG" );
53}
54
3f9bd252 55=head2 end
56
57Attempt to render a view, if needed.
58
59=cut
60
61sub end : ActionClass('RenderView') {}
62
63=head1 AUTHOR
64
65Tara L Andrews
66
67=head1 LICENSE
68
69This library is free software. You can redistribute it and/or modify
70it under the same terms as Perl itself.
71
72=cut
73
74__PACKAGE__->meta->make_immutable;
75
761;