blib/lib/IO/Automatic.pm

filter: Statementstmt 55.5% 10 / 18 Branchbran 12.5% 1 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod 0.0% 0 / 1 totaltotal 44.8% 13 / 29 CC 5 SCAR 24.8
CC
5
Cov
42%
new
14.1
BEGIN
1.0
CRAP 11.9
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package IO::Automatic;
3 1 our $VERSION = '0.03';
4  
5 1 ▶sub new {
Subroutine new: called CC=5 SCAR=26.5
Pod undocumented
6 1 my $class = shift;
7 1 my ($dest) = @_; # preserve @_ but extract $dest to examine it
8  
9 1 ▶ if (ref $dest eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dest eq "SCALAR") 1 0 1
10 1 require IO::Scalar;
11 1 return IO::Scalar->new( @_ );
12 }
13 0 ▶ return $dest if ref $dest eq 'GLOB';
Branch: 1 branch
BranchTrueFalseTotal
if ref $dest eq "GLOB" 0 0 0
14  
15 0 $! = "Don't know what to do with something of type ". ref $dest;
16 0 ▶ return if ref $dest;
Branch: 1 branch
BranchTrueFalseTotal
if ref $dest 0 0 0
17  
18 0 ▶ if ( $dest =~ /\.(?:gz|Z)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dest =~ /\.(?:gz|Z)$/) 0 0 0
19 0 require IO::Zlib;
20 0 return IO::Zlib->new( @_ );
21 }
22 0 require IO::File;
23 0 return IO::File->new( @_ );
24 }
25  
26 1 1;
27  
28 =head1 NAME
29  
30 IO::Automatic - automatically choose a suitable IO::* module
31  
32 =head1 SYNOPSIS
33  
34 use IO::Automatic;
35  
36 # scalar
37 my $scalar;
38 my $io = IO::Automatic->new( \$scalar );
39 print $io "Hello World\n";
40  
41 =head1 DESCRIPTION
42  
43 IO::Automatic provides a simple factory for creating new output
44 handles.
45  
46 Several types of automatic conversion are supplied. If no conversion
47 can be done, we return false. Only the first argument is examined to
48 determine, but all the arguments will be passed through so you can
49 also supply file mode specifications.
50  
51 =head2 Scalar references
52  
53 Scalar references are translated into IO::Scalar objects.
54  
55 =head2 Glob references
56  
57 Globs are returned untouched as it is assumed they will already be
58 suitable for use as IO handles.
59  
60 =head2 Plain scalar
61  
62 A plain scalar is assumed to be a filename and so is transformed into
63 an IO::Zlib or IO::File object as appropriate.
64  
65 =head1 AUTHOR
66  
67 Richard Clamp <richardc@unixbeard.net>
68  
69 =head1 COPYRIGHT
70  
71 Copyright (C) 2003, 2005 Richard Clamp. All Rights Reserved.
72  
73 This module is free software; you can redistribute it and/or modify it
74 under the same terms as Perl itself.
75  
76 =head1 SEE ALSO
77  
78 L<IO::File>, L<IO::Scalar>, L<IO::Zlib>
79  
80 =cut
81  
↑ Summary