line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::View::Download::Plain; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1770
|
use Moose; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
13
|
|
4
|
2
|
|
|
2
|
|
8385
|
use namespace::autoclean; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
11
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
extends 'Catalyst::View'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Catalyst::View::Download::Plain |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
0.05 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = "0.05"; |
19
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
__PACKAGE__->config( 'stash_key' => 'plain' ); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub process { |
24
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
25
|
0
|
|
|
|
|
0
|
my ($c) = @_; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
0
|
my $template = $c->stash->{ 'template' }; |
28
|
0
|
|
|
|
|
0
|
my $content = $self->render( $c, $template, $c->stash ); |
29
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
0
|
$c->res->headers->header( "Content-Type" => "text/plain" ) |
31
|
|
|
|
|
|
|
if ( $c->res->headers->header( "Content-Type" ) eq "" ); |
32
|
0
|
|
|
|
|
0
|
$c->res->body( $content ); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub render { |
36
|
1
|
|
|
1
|
1
|
642
|
my $self = shift; |
37
|
1
|
|
|
|
|
3
|
my ( $c, $template, $args ) = @_; |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
4
|
my $stash_key = $self->config->{ 'stash_key' }; |
40
|
1
|
|
33
|
|
|
44
|
my $content = $c->stash->{ $stash_key } || $c->response->body; |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
75
|
return $content; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__END__ |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# lib/MyApp/View/Download/Plain.pm |
54
|
|
|
|
|
|
|
package MyApp::View::Download::Plain; |
55
|
|
|
|
|
|
|
use base qw( Catalyst::View::Download::Plain ); |
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# lib/MyApp/Controller/SomeController.pm |
59
|
|
|
|
|
|
|
sub example_action_1 : Local { |
60
|
|
|
|
|
|
|
my ($self, $c) = @_; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $content = "Some Text"; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# To output your data just pass your content into the 'plain' key of the stash |
65
|
|
|
|
|
|
|
$c->stash->{'plain'} = $content; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Or into the body of the response for this action |
68
|
|
|
|
|
|
|
$c->response->body($content); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Finally forward processing to the Plain View |
71
|
|
|
|
|
|
|
$c->forward('MyApp::View::Download::Plain'); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 DESCRIPTION |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Takes content and outputs the content as plain text. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 SUBROUTINES |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 process |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
This method will be called by Catalyst if it is asked to forward to a component |
83
|
|
|
|
|
|
|
without a specified action. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 render |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Allows others to use this view for much more fine-grained content generation. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 CONFIG |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=over 4 |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item stash_key |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Determines the key in the stash this view will look for when attempting to |
96
|
|
|
|
|
|
|
retrieve content to process. If this key isn't found it will then look at |
97
|
|
|
|
|
|
|
$c->response->body for content. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
$c->view('MyApp::View::Download::Plain')->config->{'stash_key'} = 'content'; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=back |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 AUTHOR |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Travis Chase, C<< <gaudeon at cpan dot org> >> |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SEE ALSO |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
L<Catalyst> L<Catalyst::View> L<Catalyst::View::Download> |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 LICENSE |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This program is free software. You can redistribute it and/or modify it |
114
|
|
|
|
|
|
|
under the same terms as Perl itself. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |