| 1 | package Jifty::View; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use base qw/Jifty::Object/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Class::Trigger; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use Encode (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | =head1 NAME | ||||||||||
| 11 | |||||||||||
| 12 | Jifty::View - Base class for view modules | ||||||||||
| 13 | |||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||
| 15 | |||||||||||
| 16 | This is the base class for L<Jifty::View::Declare> and L<Jifty::View::Mason::Handler>, which are the two view plugins shipped with Jifty. Other view plugins can be built by extending this class. | ||||||||||
| 17 | |||||||||||
| 18 | =head1 METHODS | ||||||||||
| 19 | |||||||||||
| 20 | =head2 auto_send_headers | ||||||||||
| 21 | |||||||||||
| 22 | Doesn't send headers if this is a subrequest (according to the current | ||||||||||
| 23 | L<Jifty::Request>). | ||||||||||
| 24 | |||||||||||
| 25 | =cut | ||||||||||
| 26 | |||||||||||
| 27 | 0 | ▶ | sub auto_send_headers { | ||||||||
|
Subroutine
auto_send_headers: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 28 | 0 | return not Jifty->web->request->is_subrequest; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | =head2 out_method | ||||||||||
| 32 | |||||||||||
| 33 | The default output method. Sets the content-type to C<text/html; | ||||||||||
| 34 | charset=utf-8> unless a content type has already been set, and then | ||||||||||
| 35 | sends a header if need be. | ||||||||||
| 36 | |||||||||||
| 37 | =cut | ||||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | sub out_method { | ||||||||
|
Subroutine
out_method: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 40 | 0 | my $r = Jifty->web->response; | |||||||||
| 41 | |||||||||||
| 42 | # Send a header | ||||||||||
| 43 | 0 | ▶ | $r->content_type || $r->content_type('text/html; charset=utf-8'); # Set up a default | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | |||||||||||
| 45 | # We now install a new, faster out_method that doesn't have to | ||||||||||
| 46 | # keep checking whether headers have been sent. | ||||||||||
| 47 | 0 | ▶ | my $content = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||
| 48 | Jifty->web->response->{body} .= $_ | ||||||||||
| 49 | 0 | ▶ | for map { Encode::is_utf8($_) ? Encode::encode('utf8', $_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | : $_ } | ||||||||||
| 51 | @_; | ||||||||||
| 52 | 0 | }; | |||||||||
| 53 | 0 | Jifty->handler->buffer->out_method( $content ); | |||||||||
| 54 | 0 | $content->(@_); | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | =head1 SEE ALSO | ||||||||||
| 58 | |||||||||||
| 59 | L<Jifty::View::Declare>, L<Jifty::View::Declare::BaseClass>, L<Jifty::View::Mason::Handler> | ||||||||||
| 60 | |||||||||||
| 61 | =head1 LICENSE | ||||||||||
| 62 | |||||||||||
| 63 | Jifty is Copyright 2005-2010 Best Practical Solutions, LLC. | ||||||||||
| 64 | Jifty is distributed under the same terms as Perl itself. | ||||||||||
| 65 | |||||||||||
| 66 | =cut | ||||||||||
| 67 | |||||||||||
| 68 | |||||||||||
| 69 | |||||||||||
| 70 | 1 | 1; | |||||||||