source: trunk/lib/Vote/View/Latex.pm @ 194

Last change on this file since 194 was 194, checked in by nanardon, 15 years ago
  • clearly separate Catalyst Model and Vote::DB module, making test faster
  • Property svn:keywords set to Id Rev
File size: 1.5 KB
Line 
1package Vote::View::Latex;
2
3use strict;
4use base 'Vote::View::TT';
5use LaTeX::Driver;
6use File::Temp;
7
8__PACKAGE__->config(
9    TEMPLATE_EXTENSION => '.tt',
10    INCLUDE_PATH => Vote->path_to( 'root', 'latex' ),
11    PRE_PROCESS => 'includes/header.tt',
12    POST_PROCESS => 'includes/footer.tt',
13    PLUGIN_BASE => 'Vote::Template::Plugin',
14);
15
16=head1 NAME
17
18Vote::View::Latex - Latex View for Vote
19
20=head1 DESCRIPTION
21
22TT View for Vote.
23
24=cut
25
26sub process {
27    my ($self, $c) = @_;
28
29    $c->stash->{format} ||= 'pdf';
30    my $output = $self->render(
31        $c, $c->stash->{template}
32    );
33   
34    if ($c->stash->{format} eq 'tex') {
35        $c->res->body($output);
36        return;
37    }
38
39    my ($fh, $filename) = File::Temp::tempfile(
40        SUFFIX => ($c->stash->{format}),
41    );
42    close($fh);
43
44    LaTeX::Driver::hack->new(
45        source  => \$output,
46        output  => $filename,
47        format  => $c->stash->{format},
48    )->run;
49    open($fh, '<', $filename);
50    binmode($fh);
51    $c->res->body(join('', <$fh>));
52}
53
54# This is just a hack
55# Don't ask me why, but system() return -1 instead 0
56# under catalyst...
57# This is just an ugly workaround
58
59package LaTeX::Driver::hack;
60use base qw(LaTeX::Driver);
61
62sub run_command {
63    my ($self, @args) = @_;
64    $self->SUPER::run_command(@args);
65    return $self->SUPER::run_command(@args) <= 0 ? 0 : 1;
66} 
67
68=head1 SEE ALSO
69
70L<Vote>
71
72=head1 AUTHOR
73
74Thauvin Olivier
75
76=head1 LICENSE
77
78This library is free software, you can redistribute it and/or modify
79it under the same terms as Perl itself or CeCILL.
80
81=cut
82
831;
Note: See TracBrowser for help on using the repository browser.