File Coverage

blib/lib/WWW/Mechanize/Cached/GZip.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             WWW::Mechanize::Cached::GZip - like WWW::Mechanize + caching + gzip-compression
4              
5             =head1 VERSION
6              
7             Version 0.12
8              
9             =head1 SYNOPSIS
10              
11             use WWW::Mechanize::Cached::GZip;
12              
13             my $mech_cached = WWW::Mechanize::Cached::GZip->new();
14             my $response = $mech_cached->get($url);
15              
16             print "x-content-length (before unzip) = ", $response->header('x-content-length');
17             print "content-length (after unzip) = ", $response->header('content-length');
18              
19             ...
20            
21             # for the same $url - the already uncompressed $response2 is now taken from cache:
22             my $response2 = $mech_cached->get($url);
23              
24             =head1 DESCRIPTION
25              
26             The L<WWW::Mechanize::Cached::GZip> module tries to fetch a URL by requesting
27             gzip-compression from the webserver.
28              
29             Caching is done by inheriting from L<WWW::Mechanize::Cached>.
30             Constructor parameters are identically and described there.
31              
32             =head2 DECOMPRESSION
33              
34             If the response contains a header with 'Content-Encoding: gzip', it
35             decompresses the response-body in order to get the original (uncompressed) content.
36              
37             This module will help to reduce bandwith fetching webpages, if supported by the
38             webeserver. If the webserver does not support gzip-compression, no decompression
39             will be made.
40              
41             The decompression of the response is handled by L<Compress::Zlib>::memGunzip.
42              
43             There is a small webform, you can instantly test, whether a webserver supports
44             gzip-compression on a particular URL:
45             L<http://www.computerhandlung.de/www-mechanize-cached-gzip.htm>
46              
47             =head2 CACHING
48              
49             This modules is a direct subclass of L<WWW::Mechanize::Cached> and will therefore
50             accept the same constructor parameters and support any methods provided
51             by WWW::Mechanize::Cached.
52              
53             The default behavoir is to use Cache::FileCache which stores its files somewhere
54             under /tmp.
55              
56             =head2 METHODS
57              
58             =over 2
59              
60             =item prepare_request
61              
62             Adds 'Accept-Encoding' => 'gzip' to outgoing HTTP-headers before sending.
63              
64             =item send_request
65              
66             Unzips response-body if 'content-encoding' is 'gzip' and
67             corrects 'content-length' to unzipped content-length.
68              
69             =back
70              
71             =head1 SEE ALSO
72              
73             L<WWW::Mechanize::Cached>
74              
75             L<Compress::Zlib>
76              
77             =head1 AUTHOR
78              
79             Peter Giessner C<cardb@planet-elektronik.de>
80              
81             =head1 LICENCE AND COPYRIGHT
82              
83             Copyright (c) 2011, Peter Giessner C<cardb@planet-elektronik.de>.
84             All rights reserved.
85              
86             This module is free software; you can redistribute it and/or
87             modify it under the same terms as Perl itself.
88              
89             =cut
90              
91             package WWW::Mechanize::Cached::GZip;
92              
93             our $VERSION = '0.12';
94              
95 2     2   45184 use Moose;
  0            
  0            
96             extends 'WWW::Mechanize::Cached';
97             use WWW::Mechanize::GZip;
98              
99             ################################################################################
100             sub prepare_request {
101             my ($self, $request) = @_;
102            
103             # call sideclass-method to prepare request
104             return WWW::Mechanize::GZip::prepare_request($self, $request);
105             }
106              
107             ################################################################################
108             sub send_request {
109             my ($self, $request, $arg, $size) = @_;
110              
111             # call sideclass-method to make the actual request
112             return WWW::Mechanize::GZip::send_request($self, $request, $arg, $size);
113             }
114              
115             1;
116              
117             __END__