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