line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::Acme::Scramble; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23498
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2123
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Catalyst::Plugin::Acme::Scramble - tset the budnos of lieibiglty and dstraneotme how we pcvreiee wdors wtih yuor Ctyslaat apicapltion |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Version 0.03 |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=cut |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Catalyst qw/ |
20
|
|
|
|
|
|
|
Your::Regular::Plugins |
21
|
|
|
|
|
|
|
Acme::Scramble |
22
|
|
|
|
|
|
|
/; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# And observe the corrected output of your application |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Implements a potent meme about how easily we can read scrambled text |
27
|
|
|
|
|
|
|
if the first and last letters remain constant. Operates on text/plain |
28
|
|
|
|
|
|
|
and text/html served by your Catalyst application. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $skip = qr/script|style|map|area/; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub finalize { |
35
|
0
|
|
|
0
|
0
|
|
my $c = shift; |
36
|
|
|
|
|
|
|
|
37
|
0
|
0
|
0
|
|
|
|
return $c->NEXT::finalize unless $c->response->body |
38
|
|
|
|
|
|
|
and |
39
|
|
|
|
|
|
|
$c->response->content_type =~ m,^text/(plain|html),; |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
if ( $1 eq 'plain' ) |
42
|
|
|
|
|
|
|
{ |
43
|
0
|
|
|
|
|
|
_scramble_block( \$c->response->{body} ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
else |
46
|
|
|
|
|
|
|
{ |
47
|
0
|
|
|
|
|
|
require HTML::TokeParser; |
48
|
0
|
|
|
|
|
|
my $p = HTML::TokeParser->new( \$c->response->{body} ); |
49
|
0
|
|
|
|
|
|
my $repaired = ''; |
50
|
0
|
|
|
|
|
|
my @queue; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
while ( my $t = $p->get_token() ) |
53
|
|
|
|
|
|
|
{ |
54
|
0
|
0
|
|
|
|
|
push @queue, $t->[1] if $t->[0] eq 'S'; # assumes well-formed |
55
|
0
|
0
|
|
|
|
|
pop @queue if $t->[0] eq 'E'; |
56
|
0
|
0
|
0
|
|
|
|
if ( |
|
|
|
0
|
|
|
|
|
57
|
|
|
|
|
|
|
$t->[0] eq 'T' |
58
|
|
|
|
|
|
|
and |
59
|
|
|
|
|
|
|
not $t->[2] |
60
|
|
|
|
|
|
|
and |
61
|
|
|
|
|
|
|
not grep /$skip/, @queue ) |
62
|
|
|
|
|
|
|
{ |
63
|
0
|
|
|
|
|
|
my $txt = $t->[1]; |
64
|
0
|
|
|
|
|
|
_scramble_block(\$txt); |
65
|
0
|
|
|
|
|
|
$repaired .= $txt; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
else |
68
|
|
|
|
|
|
|
{ |
69
|
0
|
0
|
|
|
|
|
$repaired .= ( $t->[0] eq 'T' ) ? $t->[1] : $t->[-1]; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
0
|
|
|
|
|
|
$c->response->{body} = $repaired; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
$c->NEXT::finalize; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _scramble_block { |
79
|
0
|
|
|
0
|
|
|
my $text = shift; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
${$text} =~ s{ |
|
0
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
( (?:(?<=[^[:alpha:]])|(?<=\A)) |
83
|
|
|
|
|
|
|
(?<!&)(?-x)(?<!&#)(?x) |
84
|
|
|
|
|
|
|
(?: |
85
|
|
|
|
|
|
|
['[:alpha:]]+ | (?<!-)-(?!-) |
86
|
|
|
|
|
|
|
)+ |
87
|
|
|
|
|
|
|
(?=[^[:alpha:]]|\z) |
88
|
|
|
|
|
|
|
) |
89
|
|
|
|
|
|
|
} |
90
|
0
|
|
|
|
|
|
{_scramble_word($1)}gex; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _scramble_word { |
94
|
0
|
|
0
|
0
|
|
|
my $word = shift || return ''; |
95
|
0
|
|
|
|
|
|
my @piece = split //, $word; |
96
|
0
|
0
|
|
|
|
|
shuffle(@piece[1..$#piece-1]) |
97
|
|
|
|
|
|
|
if @piece > 2; |
98
|
0
|
|
|
|
|
|
join('', @piece); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub shuffle { |
102
|
0
|
|
|
0
|
0
|
|
for ( my $i = @_; --$i; ) { |
103
|
0
|
|
|
|
|
|
my $j = int(rand($i+1)); |
104
|
0
|
|
|
|
|
|
@_[$i,$j] = @_[$j,$i]; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 AUTHOR |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Ashley Pond V, ashley at cpan.org. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 BUGS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
I love bugs! Hymenoptera, dictyoptera, coleoptera, all of them. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Expects valid nesting. May sometimes interfere with tags that should |
117
|
|
|
|
|
|
|
be literal, like E<lt>scriptE<gt> and E<lt>styleE<gt>, when it's not |
118
|
|
|
|
|
|
|
present. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 SUPPORT |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
perldoc Catalyst::Plugin::Acme::Scramble |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
You can also look for information at: |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=over 4 |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
L<http://annocpan.org/dist/Catalyst-Plugin-Acme-Scramble> |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item * CPAN Ratings |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/Catalyst-Plugin-Acme-Scramble> |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Plugin-Acme-Scramble> |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item * Search CPAN |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
L<http://search.cpan.org/dist/Catalyst-Plugin-Acme-Scramble> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=back |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 TODO |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Support application/xhtml+xml? If it's served that way, or even as any |
151
|
|
|
|
|
|
|
XML, we could use an XML parser and just scramble the #text parts. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 SEE ALSO |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
L<Catalyst>, L<Catalyst::Runtime>. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Copyright 2006 Ashley Pond V, all rights reserved. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
This program is free software; you can redistribute it and modify it |
162
|
|
|
|
|
|
|
under the same terms as Perl itself. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
1; # End of Catalyst::Plugin::Acme::Scramble |