File Coverage

blib/lib/Filter/gunzip.pm
Criterion Covered Total %
statement 13 15 86.6
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 18 20 90.0


line stmt bran cond sub pod time code
1             # Copyright 2010, 2011, 2013, 2014 Kevin Ryde
2              
3             # This file is part of Filter-gunzip.
4             #
5             # Filter-gunzip is free software; you can redistribute it and/or modify it
6             # under the terms of the GNU General Public License as published by the Free
7             # Software Foundation; either version 3, or (at your option) any later
8             # version.
9             #
10             # Filter-gunzip is distributed in the hope that it will be useful, but
11             # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12             # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13             # for more details.
14             #
15             # You should have received a copy of the GNU General Public License along
16             # with Filter-gunzip. If not, see .
17              
18             package Filter::gunzip;
19 1     1   768 use strict;
  1         2  
  1         43  
20 1     1   5 use Carp;
  1         2  
  1         66  
21 1     1   6 use DynaLoader;
  1         2  
  1         24  
22 1     1   8 use PerlIO;
  1         2  
  1         9  
23 1     1   534 use PerlIO::gzip;
  0            
  0            
24              
25             use vars qw($VERSION @ISA);
26             $VERSION = 6;
27             @ISA = ('DynaLoader');
28              
29             __PACKAGE__->bootstrap($VERSION);
30              
31             # uncomment this to run the ### lines
32             # use Smart::Comments;
33              
34              
35             sub import {
36             my ($class) = @_;
37              
38             my $filters = _rsfp_filters();
39             ### _rsfp_filters(): scalar(@{$filters})
40              
41             if ($filters && ! @{$filters}) {
42             my $fh;
43             ### _rsfp(): _rsfp()
44             if (($fh = _rsfp())
45             && eval { require PerlIO;
46             require PerlIO::gzip;
47             1 }) {
48             ### fh: $fh
49             ### tell: tell($fh)
50              
51             my @layers = PerlIO::get_layers($fh);
52             ### layers: \@layers
53              
54             if ($layers[-1] eq 'crlf') {
55             binmode ($fh, ':pop')
56             or croak "Oops, cannot pop crlf layer: $!";
57             }
58              
59             binmode ($fh, ':gzip')
60             or croak "Cannot push gzip layer: $!";
61              
62             if ($layers[-1] eq 'crlf') {
63             binmode ($fh, ':crlf')
64             or croak "Oops, cannot re-push crlf layer: $!";
65             }
66              
67             # @layers = PerlIO::get_layers($fh);
68             # ### pushed gzip: \@layers
69             return;
70             }
71             }
72              
73             require Filter::gunzip::Filter;
74             Filter::gunzip::Filter->import;
75             }
76              
77             1;
78             __END__