line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::Acme::LOLCAT; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24839
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
425
|
use Acme::LOLCAT (); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Catalyst::Plugin::Acme::LOLCAT - IM IN UR CATALYST APLACASHUN REWRITIN YUR OUTPUTS. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.03 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = "0.03"; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
See L<Acme::LOLCAT> if you don't already know what this will do to |
21
|
|
|
|
|
|
|
your Catalyst plain text and HTML output. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use Catalyst qw/ |
24
|
|
|
|
|
|
|
Your::Regular::Plugins |
25
|
|
|
|
|
|
|
Acme::LOLCAT |
26
|
|
|
|
|
|
|
/; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# And observe the corrected output of your application |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $skip = qr/\Ascript|style\z/; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub finalize { |
35
|
|
|
|
|
|
|
my $c = shift; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
return $c->NEXT::finalize unless $c->response->body |
38
|
|
|
|
|
|
|
and |
39
|
|
|
|
|
|
|
$c->response->content_type =~ m,^text/(plain|html),; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
if ( $1 eq 'plain' ) |
42
|
|
|
|
|
|
|
{ |
43
|
|
|
|
|
|
|
$c->response->{body} = Acme::LOLCAT::translate($c->response->{body}); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
else |
46
|
|
|
|
|
|
|
{ |
47
|
|
|
|
|
|
|
require HTML::TokeParser; |
48
|
|
|
|
|
|
|
my $p = HTML::TokeParser->new( \$c->response->{body} ); |
49
|
|
|
|
|
|
|
my $repaired = ''; |
50
|
|
|
|
|
|
|
my @queue; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
while ( my $t = $p->get_token() ) |
53
|
|
|
|
|
|
|
{ |
54
|
|
|
|
|
|
|
push @queue, $t->[1] if $t->[0] eq 'S'; # assumes well-formed |
55
|
|
|
|
|
|
|
pop @queue if $t->[0] eq 'E' |
56
|
|
|
|
|
|
|
or |
57
|
|
|
|
|
|
|
( $t->[0] eq 'S' and $t->[-1] =~ m,/>\z, ); # self-closer |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
if ( |
60
|
|
|
|
|
|
|
$t->[0] eq 'T' |
61
|
|
|
|
|
|
|
and |
62
|
|
|
|
|
|
|
not $t->[2] |
63
|
|
|
|
|
|
|
and |
64
|
|
|
|
|
|
|
not grep /$skip/, @queue ) |
65
|
|
|
|
|
|
|
{ |
66
|
|
|
|
|
|
|
my $txt = $t->[1] =~ /\w/ ? Acme::LOLCAT::translate($t->[1]) : $t->[1]; |
67
|
|
|
|
|
|
|
$repaired .= $txt; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else |
70
|
|
|
|
|
|
|
{ |
71
|
|
|
|
|
|
|
$repaired .= ( $t->[0] eq 'T' ) ? $t->[1] : $t->[-1]; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
$c->response->{body} = $repaired; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$c->NEXT::finalize; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 AUTHOR |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Ashley Pond V, ashley at cpan.org. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 BUGS |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
I love bugs! Hymenoptera, dictyoptera, coleoptera, all of them. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Expects valid nesting. May sometimes interfere with tags that should |
89
|
|
|
|
|
|
|
be literal, like E<lt>scriptE<gt> and E<lt>styleE<gt>, when it's not |
90
|
|
|
|
|
|
|
present. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 TODO |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Targeted tags in config file? |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 SUPPORT |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
perldoc Catalyst::Plugin::Acme::LOLCAT |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
You can also look for information at: |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=over 4 |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
L<http://annocpan.org/dist/Catalyst-Plugin-Acme-LOLCAT> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item * CPAN Ratings |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/Catalyst-Plugin-Acme-LOLCAT> |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Plugin-Acme-LOLCAT> |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item * Search CPAN |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
L<http://search.cpan.org/dist/Catalyst-Plugin-Acme-LOLCAT> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=back |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 SEE ALSO |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
L<Acme::LOLCAT>, L<Catalyst::Plugin::Acme::Scramble>, L<Catalyst>, |
127
|
|
|
|
|
|
|
L<Catalyst::Runtime>. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Copyright (c) 2007 Ashley Pond V, all rights reserved. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This program is free software; you can redistribute it and modify it |
134
|
|
|
|
|
|
|
under the same terms as Perl itself. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; # End of Catalyst::Plugin::Acme::LOLCAT |