Merge branch 'master' of github.com:tla/stemmatology
[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
18TreeOfTexts::Controller::Root - Root Controller for TreeOfTexts
19
20=head1 DESCRIPTION
21
22[enter your description here]
23
24=head1 METHODS
25
3f9bd252 26sub get_graph :Local {
27 my( $self, $c ) = @_;
28 # If called interactively, we have params 'display', 'output', 'witnesses'
29 # If called non-interactively, we look at headers and content.
30 # The body is actually a File::Temp object; this is undocumented but
31 # so it seems to be.
cbd0c7d9 32 my $dotfile;
33 $DB::single = 1;
34 my $must_unlink = 0;
35 if( $c->request->params->{'dot'} ) {
36 # Make a File::Temp object.
37 my $tmpfile = File::Temp->new( UNLINK => 0 );
38 print $tmpfile $c->request->params->{'dot'};
39 $dotfile = $tmpfile->filename;
40 $must_unlink = 1;
41 } else {
42 $dotfile = $c->request->body;
43 }
3f9bd252 44 my $format = 'svg';
45
46 # Render the dot in the given format.
47 my $collation = Text::Tradition::Collation->new();
cbd0c7d9 48 my $stemma = Text::Tradition::Stemma->new( 'collation' => $collation, 'dot' => $dotfile );
49 unlink( $dotfile ) if $must_unlink;
3f9bd252 50 $c->stash->{result} = $stemma->as_svg;
51 $c->forward( "View::SVG" );
52}
53
54=head2 default
55
56Standard 404 error page
57
58=cut
59
60sub default :Path {
61 my ( $self, $c ) = @_;
62 $c->response->body( 'Page not found' );
63 $c->response->status(404);
64}
65
66=head2 end
67
68Attempt to render a view, if needed.
69
70=cut
71
72sub end : ActionClass('RenderView') {}
73
74=head1 AUTHOR
75
76Tara L Andrews
77
78=head1 LICENSE
79
80This library is free software. You can redistribute it and/or modify
81it under the same terms as Perl itself.
82
83=cut
84
85__PACKAGE__->meta->make_immutable;
86
871;