File Coverage

blib/lib/Filesys/Type.pm
Criterion Covered Total %
statement 23 23 100.0
branch 1 2 50.0
condition n/a
subroutine 8 8 100.0
pod 3 3 100.0
total 35 36 97.2


line stmt bran cond sub pod time code
1              
2             package Filesys::Type;
3 1     1   24430 use strict;
  1         3  
  1         52  
4              
5             BEGIN {
6 1     1   6 use Exporter ();
  1         1  
  1         26  
7 1     1   6 use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
  1         19  
  1         184  
8 1     1   2 $VERSION = 0.02;
9 1         18 @ISA = qw (Exporter);
10             #Give a hoot don't pollute, do not export more than needed by default
11 1         3 @EXPORT = qw ();
12 1         3 @EXPORT_OK = qw (fstype case diagnose);
13 1         50 %EXPORT_TAGS = (all => [qw(fstype case diagnose)]);
14             }
15              
16              
17             =head1 NAME
18              
19             Filesys::Type - Portable way of determining the type of a file system.
20              
21             =head1 SYNOPSIS
22              
23             use Filesys::Type qw(fstype);
24            
25             ...
26             my $fs = '/mnt/hda7';
27             warn "Not able to share with Windows"
28             if (fstype($fs) ne 'vfat');
29              
30              
31             =head1 DESCRIPTION
32              
33             This module provides a portable interface, either to Unix mount -n
34             or to Win32::filesys or to another native OS interface.
35              
36             The module is pluggable, which will allow for other operating systems
37             to be added in future without needing to change the core module.
38              
39             =head2 fstype
40              
41             This exportable function takes a string, which is a file or directory
42             path, and returns the file system type, e.g. vfat, ntfs, ext2, etc.
43             Note that the exact string returned is operating system dependent.
44              
45             =head2 case
46              
47             This is another exportable function that returns the case sensitivity
48             of a file system. It either takes a file system type as returned by
49             fstype, or a path as input. It returns one of the following:
50              
51             =over 4
52              
53             =item C
54              
55             like Unix ext2, ext3, etc.
56              
57             =item C
58              
59             VMS ODS-2 filenames are case insensitive. System services return the
60             names in upper case, but the CRTL which provides globbing and the
61             command line interface turns to lower case.
62              
63             =item C
64              
65             This is the behaviour of Windows file systems, FAT16, FAT32 and NTFS.
66             The file names are case insensitive, i.e. foo, Foo and FOO refer to the
67             same file, but the initial case of the letters of the file name is
68             preserved from the time it was created.
69              
70             =back
71              
72             =head2 C
73              
74             Use this to determine what went wrong if fstype returned undef. Returns
75             a string suitable for printing in a log or on stderr.
76              
77             =head1 SECURITY
78              
79             Note that some platforms use backtick shell commands to derive information
80             about the file systems. Be careful that a rogue user could execute
81             operating system commands by injecting into the path.
82              
83             It is recommended only to pass in untainted strings. See perldoc perlsec
84             for details of running in taint mode, and for a description of how to untaint
85             a string passed in from outside.
86              
87             =head1 BUGS
88              
89             Please report bugs to http://rt.cpan.org. Post to bug-filesys-type@rt.cpan.org
90              
91              
92             =head1 HISTORY
93              
94             0.01 Sun Jun 12 2005
95             - original version; created by ExtUtils::ModuleMaker 0.32
96              
97             0.02 Fri Jul 08 2005
98             - Change plugins to be OO. Add diagnostic facility to see
99             more about failing tests on some platforms.
100              
101             =head1 AUTHOR
102              
103             I. Williams
104             ivorw@cpan.org
105              
106             =head1 COPYRIGHT
107              
108             This program is free software; you can redistribute
109             it and/or modify it under the same terms as Perl itself.
110              
111             The full text of the license can be found in the
112             LICENSE file included with this module.
113              
114              
115             =head1 SEE ALSO
116              
117             L.
118              
119             =cut
120              
121 1     1   1017 use Module::Pluggable instantiate => 'new';
  1         11797  
  1         8  
122             our ($plugin) = grep {defined $_} __PACKAGE__->plugins;
123             warn "failed to detect suitable Filesys::Type::Plugin"
124             unless defined $plugin;
125              
126             sub fstype {
127 5     5 1 55 $plugin->fstype(shift);
128             }
129              
130             our %case_sensitivity = (
131             msdos => 'insensitive',
132             umsdos => 'insensitive',
133             vfat => 'insensitive',
134             ntfs => 'insensitive',
135             minix => 'sensitive',
136             xiafs => 'sensitive',
137             ext2 => 'sensitive',
138             ext3 => 'sensitive',
139             iso9660 => 'sensitive',
140             hpfs => 'sensitive',
141             sysv => 'sensitive',
142             nfs => 'sensitive',
143             smb => 'insensitive',
144             ncpfs => 'insensitive',
145             FAT => 'insensitive',
146             FAT32 => 'insensitive',
147             CDFS => 'insensitive',
148             NTFS => 'insensitive',
149             'ODS-2' => 'lower',
150             );
151              
152             sub case {
153 2     2 1 1001 my $fs = shift;
154              
155 2 50       14 return $case_sensitivity{$fs} if exists $case_sensitivity{$fs};
156 2         20 $fs = fstype($fs);
157              
158 2         79 $case_sensitivity{$fs};
159             }
160              
161             sub diagnose {
162 1     1 1 1899 $plugin->diagnose;
163             }
164              
165             1; #this line is important and will help the module return a true value
166             __END__