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