| 1 | package Cache::Memcached::Fast::CGI; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | =head1 NAME | ||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | Cache::Memcached::Fast::CGI - Capture the STDOUT for Memcached in a pure cgi program! | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | =head1 VERSION | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | Version 0.06 | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | =cut | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 1 | our $VERSION = '0.06'; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 1 | ▶ | use Cache::Memcached::Fast; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 1 | ▶ | use IO::Capture::Stdout; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 1 | ▶ | use Exporter; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||
| 23 | 1 | our @EXPORT = qw(setup get add start end auto_end); | |||||||||||||||||||
| 24 | 1 | our @EXPORT_ok = qw(); | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 27 | 0 | my $class = shift; | |||||||||||||||||||
| 28 | 0 | ▶ | $class = ref $class || $class; | ||||||||||||||||||
|
Condition0%0/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table0%0/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 29 | 0 | my $self ={}; | |||||||||||||||||||
| 30 | 0 | bless $self,$class; | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 0 | $self->{'cmf'} = Cache::Memcached::Fast->new(@_); | |||||||||||||||||||
| 33 | 0 | $self->{'ics'} = new IO::Capture::Stdout; | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 0 | return $self; | |||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 0 | ▶ | sub setup { | ||||||||||||||||||
|
Subroutine
setup: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 39 | 0 | my $self = shift; | |||||||||||||||||||
| 40 | 0 | my %set = @_; | |||||||||||||||||||
| 41 | 0 | ▶ | while(my($k,$v) = each %set){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 0 | $self -> {$k} = $v; | |||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 0 | ▶ | sub get { | ||||||||||||||||||
|
Subroutine
get: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 47 | 0 | my $self = shift; | |||||||||||||||||||
| 48 | 0 | my $key = shift; | |||||||||||||||||||
| 49 | 0 | my $value = $self->{'cmf'}->get($key); | |||||||||||||||||||
| 50 | 0 | return $value; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 0 | ▶ | sub add { | ||||||||||||||||||
|
Subroutine
add: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 54 | 0 | my $self = shift; | |||||||||||||||||||
| 55 | 0 | $self->{'cmf'}->add(@_); | |||||||||||||||||||
| 56 | 0 | return 1; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 0 | ▶ | sub start { | ||||||||||||||||||
|
Subroutine
start: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 60 | 0 | my $self = shift; | |||||||||||||||||||
| 61 | 0 | $self->{'ics'} -> start(); | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 0 | ▶ | sub end { | ||||||||||||||||||
|
Subroutine
end: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 65 | 0 | my $self = shift; | |||||||||||||||||||
| 66 | 0 | $self->{'ics'} -> stop(); | |||||||||||||||||||
| 67 | 0 | my $re = join '',$self->{'ics'}->read(); | |||||||||||||||||||
| 68 | 0 | return $re; | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 0 | ▶ | sub auto_end { | ||||||||||||||||||
|
Subroutine
auto_end: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 72 | 0 | my $self = shift; | |||||||||||||||||||
| 73 | 0 | my $key = shift; | |||||||||||||||||||
| 74 | 0 | my $time = shift; | |||||||||||||||||||
| 75 | 0 | $self->{'ics'} -> stop(); | |||||||||||||||||||
| 76 | 0 | my $re = join '',$self->{'ics'}->read(); | |||||||||||||||||||
| 77 | 0 | $self->{'cmf'}->add($key,$re,$time); | |||||||||||||||||||
| 78 | 0 | print $re; | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | =head1 SYNOPSIS | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | use Cache::Memcached::Fast::CGI; | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | my $cmfc = Cache::Memcached::Fast::CGI->new({ | ||||||||||||||||||||
| 87 | servers => ['localhost:11211'], | ||||||||||||||||||||
| 88 | connect_timeout => 0.3 | ||||||||||||||||||||
| 89 | ## ... | ||||||||||||||||||||
| 90 | }); | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | my $key = $ENV{'SCRIPT_FILENAME'}.'?'.$ENV{'QUERY_STRING'}; | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | ## Retrieve values | ||||||||||||||||||||
| 95 | my $value = $cmfc->get($key); | ||||||||||||||||||||
| 96 | print $value and exit if $value; | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | ## Start capture | ||||||||||||||||||||
| 99 | $cmfc->start(); | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | print "Content-type: text/html;charset=utf-8\n\n"; | ||||||||||||||||||||
| 102 | print "<html><body>"; | ||||||||||||||||||||
| 103 | print "hello world -- 1<br>"; | ||||||||||||||||||||
| 104 | ## ... | ||||||||||||||||||||
| 105 | print "hello world -- 2<br>"; | ||||||||||||||||||||
| 106 | print "</body></html>"; | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | ## Automatic end of the capture | ||||||||||||||||||||
| 109 | $cmfc->auto_end($key); | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | exit; | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | =head1 SUBROUTINES/METHODS | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | =head2 add | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | # Add the key and valuse into memcahced | ||||||||||||||||||||
| 119 | $cmfc->add($key,$value,$time); | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | =head2 end | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | ## End capture | ||||||||||||||||||||
| 124 | my $captured = $cmfc->end(); | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | =head3 auto_end | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | ## Automatic end of the capture | ||||||||||||||||||||
| 129 | $cmfc->auto_end($key,$time); | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | =head1 AUTHOR | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | =HITSU, C<< <hitsubunnu at gmail.com> >> | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | =head1 BUGS | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | Please report any bugs or feature requests to C<bug-cache-memcached-fast-cgi at rt.cpan.org>, or through | ||||||||||||||||||||
| 138 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Cache-Memcached-Fast-CGI>. I will be notified, and then you'll | ||||||||||||||||||||
| 139 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | =head1 SUPPORT | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | perldoc Cache::Memcached::Fast::CGI | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | You can also look for information at: | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | =over 4 | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | =item * RT: CPAN's request tracker | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Cache-Memcached-Fast-CGI> | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | L<http://annocpan.org/dist/Cache-Memcached-Fast-CGI> | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | =item * CPAN Ratings | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | L<http://cpanratings.perl.org/d/Cache-Memcached-Fast-CGI> | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | =item * Search CPAN | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | L<http://search.cpan.org/dist/Cache-Memcached-Fast-CGI/> | ||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | =back | ||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | Copyright 2010 =Hitsu Bunnu. | ||||||||||||||||||||
| 180 | |||||||||||||||||||||
| 181 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||
| 182 | under the terms of either: the GNU General Public License as published | ||||||||||||||||||||
| 183 | by the Free Software Foundation; or the Artistic License. | ||||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | See http://dev.perl.org/licenses/ for more information. | ||||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | =cut | ||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | 1 | 1; | |||||||||||||||||||