| 1 | package Catalyst::View::Embperl; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | our $VERSION = '0.02'; | |||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use base qw( Catalyst::View ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | #use File::Spec; | ||||||||||
| 8 | 1 | ▶ | use Embperl; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use NEXT; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | __PACKAGE__->mk_accessors(qw/ rootdir dumper /); | |||||||||
| 12 | |||||||||||
| 13 | =head1 NAME | ||||||||||
| 14 | |||||||||||
| 15 | Catalyst::View::Embperl - Embperl View Class | ||||||||||
| 16 | |||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||
| 18 | |||||||||||
| 19 | # use the helper (XXX TODO) | ||||||||||
| 20 | create.pl view Embperl Epl | ||||||||||
| 21 | |||||||||||
| 22 | # lib/MyApp/View/Epl.pm | ||||||||||
| 23 | package MyApp::View::Epl; | ||||||||||
| 24 | |||||||||||
| 25 | use base 'Catalyst::View::Embperl'; | ||||||||||
| 26 | |||||||||||
| 27 | __PACKAGE__->config( | ||||||||||
| 28 | ); | ||||||||||
| 29 | |||||||||||
| 30 | 1; | ||||||||||
| 31 | |||||||||||
| 32 | # Meanwhile, maybe in an 'end' action | ||||||||||
| 33 | $c->forward('MyApp::View::Epl'); | ||||||||||
| 34 | |||||||||||
| 35 | |||||||||||
| 36 | =head1 DESCRIPTION | ||||||||||
| 37 | |||||||||||
| 38 | This is the C<Embperl> view class. Your subclass should inherit from this | ||||||||||
| 39 | class. | ||||||||||
| 40 | |||||||||||
| 41 | =head2 METHODS | ||||||||||
| 42 | |||||||||||
| 43 | =over 4 | ||||||||||
| 44 | |||||||||||
| 45 | =item new | ||||||||||
| 46 | |||||||||||
| 47 | The constructor for the Embperl view. | ||||||||||
| 48 | |||||||||||
| 49 | =cut | ||||||||||
| 50 | |||||||||||
| 51 | |||||||||||
| 52 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 53 | 0 | my($class, $c, $arguments) = @_; | |||||||||
| 54 | |||||||||||
| 55 | 0 | my $self = $class->NEXT::new($c); | |||||||||
| 56 | |||||||||||
| 57 | 0 | for my $field (keys %$arguments) { | |||||||||
| 58 | 0 | ▶ | if ($self->can($field)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 0 | $self->$field($arguments->{$field}); | |||||||||
| 60 | } else { | ||||||||||
| 61 | 0 | $c->log->debug("Unkown config parameter '$field'"); | |||||||||
| 62 | } | ||||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 0 | return $self; | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | =item process | ||||||||||
| 69 | |||||||||||
| 70 | Renders the template specified in C<< $c->stash->{template} >> | ||||||||||
| 71 | Template arguments are C<$c>. Output is stored in C<< | ||||||||||
| 72 | $c->response->body >>. | ||||||||||
| 73 | |||||||||||
| 74 | =cut | ||||||||||
| 75 | |||||||||||
| 76 | 0 | ▶ | sub process { | ||||||||
|
Subroutine
process: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 77 | 0 | my ( $self, $c ) = @_; | |||||||||
| 78 | |||||||||||
| 79 | 0 | my $template = $c->stash->{template}; | |||||||||
| 80 | |||||||||||
| 81 | 0 | ▶ | unless ($template) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | 0 | ▶ | $c->log->debug('No template specified for rendering') if $c->debug; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 0 | return 0; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 0 | ▶ | $c->log->debug(qq/Rendering template "$template"/) if $c->debug; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | |||||||||||
| 88 | 0 | my $body; | |||||||||
| 89 | |||||||||||
| 90 | # use Execute | ||||||||||
| 91 | # cf http://www3.ecos.de/embperl/pod/doc/doc13/HTML/Embperl.-page-3-.htm#sect_4 | ||||||||||
| 92 | |||||||||||
| 93 | 0 | my $template_root = $self->rootdir; | |||||||||
| 94 | |||||||||||
| 95 | 0 | eval { | |||||||||
| 96 | 0 | Embperl::Execute ({ | |||||||||
| 97 | inputfile => "$template_root/$template", | ||||||||||
| 98 | mtime => 1, | ||||||||||
| 99 | output => \$body | ||||||||||
| 100 | }); | ||||||||||
| 101 | }; | ||||||||||
| 102 | 0 | ▶ | if ( my $error = $@ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 103 | 0 | chomp $error; | |||||||||
| 104 | 0 | $error = "Couldn't render template \"$template\". Error: \"$error\""; | |||||||||
| 105 | 0 | $c->log->error($error); | |||||||||
| 106 | 0 | $c->error($error); | |||||||||
| 107 | 0 | return 0; | |||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | 0 | ▶ | unless ( $c->response->headers->content_type ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 111 | 0 | $c->res->headers->content_type('text/html; charset=utf-8'); | |||||||||
| 112 | } | ||||||||||
| 113 | |||||||||||
| 114 | 0 | $c->response->body( $body ); | |||||||||
| 115 | |||||||||||
| 116 | 0 | return 1; | |||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | =item config | ||||||||||
| 120 | |||||||||||
| 121 | This allows your view subclass to pass additional settings to the | ||||||||||
| 122 | Embperl config hash. | ||||||||||
| 123 | |||||||||||
| 124 | =back | ||||||||||
| 125 | |||||||||||
| 126 | =head1 SEE ALSO | ||||||||||
| 127 | |||||||||||
| 128 | L<Embperl>, L<Catalyst>, L<Catalyst::Base>. | ||||||||||
| 129 | |||||||||||
| 130 | =head1 AUTHOR | ||||||||||
| 131 | |||||||||||
| 132 | Christophe Le Bars, C<clb@2fp.net> | ||||||||||
| 133 | |||||||||||
| 134 | =head1 COPYRIGHT | ||||||||||
| 135 | |||||||||||
| 136 | This program is free software, you can redistribute it and/or modify it | ||||||||||
| 137 | under the same terms as Perl itself. | ||||||||||
| 138 | |||||||||||
| 139 | =cut | ||||||||||
| 140 | |||||||||||
| 141 | 1 | 1; | |||||||||