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 | |
3f9bd252 |
26 | sub 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 | |
56 | Standard 404 error page |
57 | |
58 | =cut |
59 | |
60 | sub default :Path { |
61 | my ( $self, $c ) = @_; |
62 | $c->response->body( 'Page not found' ); |
63 | $c->response->status(404); |
64 | } |
65 | |
66 | =head2 end |
67 | |
68 | Attempt to render a view, if needed. |
69 | |
70 | =cut |
71 | |
72 | sub end : ActionClass('RenderView') {} |
73 | |
74 | =head1 AUTHOR |
75 | |
76 | Tara L Andrews |
77 | |
78 | =head1 LICENSE |
79 | |
80 | This library is free software. You can redistribute it and/or modify |
81 | it under the same terms as Perl itself. |
82 | |
83 | =cut |
84 | |
85 | __PACKAGE__->meta->make_immutable; |
86 | |
87 | 1; |