File Coverage

blib/lib/Filter/PerlTags/Extra.pm
Criterion Covered Total %
statement 29 35 82.8
branch 10 14 71.4
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 45 56 80.3


line stmt bran cond sub pod time code
1             package Filter::PerlTags::Extra;
2              
3 1     1   24371 use 5.006;
  1         5  
  1         84  
4 1     1   6 use strict;
  1         2  
  1         45  
5 1     1   5 use warnings FATAL => 'all';
  1         6  
  1         102  
6              
7             =head1 NAME
8              
9             Filter::PerlTags::Extra - More mixed Perl/HTML, with some CGI built-in
10              
11             =head1 VERSION
12              
13             Version 0.01
14              
15             =cut
16              
17             our $VERSION = '0.01';
18              
19              
20             =head1 SYNOPSIS
21              
22             #!/usr/bin/perl -w
23             use Filter::PerlTags::Extra;
24            
25            
26            
27            
28            
29            
30             >
31            
32            
33            
34             You've been on this page
35             $SESSION{count} times today!
36            
37            
38              
39             The module sends a session cookie in the header. That is all. If you want more,
40             you'll probably need to look elsewhere, or ask me for features.
41              
42             ALL the additions to the code are done per line and do not break lines,
43             so if your script breaks, and you'll see the errors because of fatalsToBrowser,
44             the line numbers you see should correspond EXACTLY with those in your source.
45              
46              
47             =head1 EXPORT
48              
49             This is a filter, so it doesn't exactly export things, but you will end up with
50             some variables in your space:
51              
52             %SESSION
53            
54             A session cookie is sent to the browser and any modifications you make to
55             %SESSION are stored and reloaded next time the user visits (temporary though)
56              
57             %Q
58              
59             As got by CGI->Vars. This contains the data from GET, POST, etc.
60              
61             Also, the filter adds the following to the start of your code:
62              
63             use CGI qw/:standard :cgi-lib/;
64             use CGI::Carp qw(fatalsToBrowser);
65             use CGI::Cookie;
66             use MIME::Base64;
67             use Data::Dumper;
68             use Time::HiRes qw/time/;
69              
70             So all the exports from that are in your space too, lucky you!
71              
72             The results of
73              
74             CGI::Cookie->fetch;
75            
76             are stored in
77              
78             %COOKIES
79              
80             =head1 AUTHOR
81              
82             Jimi Wills, C<< >>
83              
84             =head1 BUGS
85              
86             Please report any bugs or feature requests to C, or through
87             the web interface at L. I will be notified, and then you'll
88             automatically be notified of progress on your bug as I make changes.
89              
90              
91              
92              
93             =head1 SUPPORT
94              
95             You can find documentation for this module with the perldoc command.
96              
97             perldoc Filter::PerlTags::Extra
98              
99              
100             You can also look for information at:
101              
102             =over 4
103              
104             =item * RT: CPAN's request tracker (report bugs here)
105              
106             L
107              
108             =item * AnnoCPAN: Annotated CPAN documentation
109              
110             L
111              
112             =item * CPAN Ratings
113              
114             L
115              
116             =item * Search CPAN
117              
118             L
119              
120             =back
121              
122              
123             =head1 ACKNOWLEDGEMENTS
124              
125              
126             =head1 LICENSE AND COPYRIGHT
127              
128             Copyright 2013 Jimi Wills.
129              
130             This program is free software; you can redistribute it and/or modify it
131             under the terms of the the Artistic License (2.0). You may obtain a
132             copy of the full license at:
133              
134             L
135              
136             Any use, modification, and distribution of the Standard or Modified
137             Versions is governed by this Artistic License. By using, modifying or
138             distributing the Package, you accept this license. Do not use, modify,
139             or distribute the Package, if you do not accept this license.
140              
141             If your Modified Version has been derived from a Modified Version made
142             by someone other than you, you are nevertheless required to ensure that
143             your Modified Version complies with the requirements of this license.
144              
145             This license does not grant you the right to use any trademark, service
146             mark, tradename, or logo of the Copyright Holder.
147              
148             This license includes the non-exclusive, worldwide, free-of-charge
149             patent license to make, have made, use, offer to sell, sell, import and
150             otherwise transfer the Package with respect to any patent claims
151             licensable by the Copyright Holder that are necessarily infringed by the
152             Package. If you institute patent litigation (including a cross-claim or
153             counterclaim) against any party alleging that the Package constitutes
154             direct or contributory patent infringement, then this Artistic License
155             to you shall terminate on the date that such litigation is filed.
156              
157             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
158             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
159             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
160             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
161             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
162             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
163             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
164             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
165              
166              
167             =cut
168              
169 1     1   911 use Filter::Util::Call;
  1         1136  
  1         555  
170              
171             our $begin = q`use CGI qw/:standard :cgi-lib/; use CGI::Carp qw(fatalsToBrowser); use CGI::Cookie; use MIME::Base64; use Data::Dumper; use Time::HiRes qw/time/; sub sessionID { foreach(encode_base64( pack "F*", time, rand, rand, rand, rand )){ tr!=+/!_.-!; return $_; }} our %COOKIES = CGI::Cookie->fetch; $SESSION::ID = $COOKIES{'sid'} ? $COOKIES{'sid'}->value : sessionID(); $SESSION::PATH = $CGITempFile::TMPDIRECTORY.'/session.'; our %SESSION = (); my $fn = $SESSION::PATH . $SESSION::ID; if( -e $fn ){ open(my $fh, '<', $fn) or carp "Could not read $fn: $!"; my $f = $/; undef $/; my $VAR1 = {}; eval(<$fh>); $/ = $f; close($fh); %SESSION = %$VAR1; } print header(-cookie=>[CGI::Cookie->new(-name=>'sid',-value=>$SESSION::ID)]); our %Q = %{scalar Vars()};`;
172              
173             our $end = q`my $fn = $SESSION::PATH . $SESSION::ID; open(my $fh, '>', $fn) or carp "Could not write $fn: $!"; print $fh Dumper \%SESSION; close($fh);`;
174              
175             our $STATE = 'START';
176             sub import {
177 1     1   11 my ($type) = @_;
178 1         3 my ($ref) = [];
179 1         4 filter_add(bless $ref);
180             }
181             sub filter {
182 3     3 0 88911 my ($self) = @_;
183 3         6 my ($status);
184 3 100       65 if( ($status = filter_read()) > 0 ){
185 2 100       12 my $CODE = $STATE eq 'TEXT' ? 'print qq!' : '';
186 2 100       8 if($STATE eq 'START'){
187 1         62 $STATE = 'TEXT';
188 1         4 $CODE = $begin . 'print qq!';
189             }
190 2         12 foreach(split /((?:<\?|\?>).*?)/){
191 2 50       13 if(/^<\?/){
    50          
192 0         0 s/^<\?//;
193 0         0 $STATE = 'PERL';
194 0         0 $CODE .= '!;';
195             }
196             elsif(/^\?>/) {
197 0         0 s/^\?>//;
198 0         0 $STATE = 'TEXT';
199 0         0 $CODE .= 'print qq!';
200             }
201 2 50       9 s/\!/\\!/g if $STATE eq 'TEXT';
202 2         7 $CODE .= $_;
203             }
204 2 50       10 $_ = $CODE . ($STATE eq 'TEXT' ? '!;' : '');
205 2         9 s``!; $end print qq!`i;
206             }
207 3         2298 $status;
208             }
209              
210             1; # End of Filter::PerlTags::Extra