File Coverage

blib/lib/Tie/FileSystem/System.pm
Criterion Covered Total %
statement 12 23 52.1
branch 0 2 0.0
condition n/a
subroutine 4 5 80.0
pod 0 1 0.0
total 16 31 51.6


line stmt bran cond sub pod time code
1             #-----------------------------------------------------------------------
2             # Copyright 2003-2007 Vadim V. Kouevda,
3             # "KAITS, Inc." All rights reserved.
4             #-----------------------------------------------------------------------
5             # $Id: System.pm,v 2.13 2007/03/21 00:11:01 vadim Exp $
6             #-----------------------------------------------------------------------
7             # Authors: Vadim V. Kouevda initdotd@gmail.com
8             #-----------------------------------------------------------------------
9             # Description: This is an add-on definitions for file processing.
10             # It is supposed to handle files, which can be classified as
11             # "system".
12             #-----------------------------------------------------------------------
13              
14             package Tie::FileSystem::System;
15              
16 2     2   21425 use vars qw($VERSION @ISA @EXPORT);
  2         4  
  2         140  
17 2     2   11 use strict;
  2         4  
  2         72  
18 2     2   10 use Exporter;
  2         7  
  2         85  
19 2     2   1316 use Data::Dumper;
  2         12009  
  2         729  
20              
21             #-----------------------------------------------------------------------
22              
23             $VERSION = sprintf("%d.%d", q$Revision: 2.13 $ =~ /(\d+)\.(\d+)/);
24             @ISA = qw(Exporter);
25             @EXPORT = qw(passwd);
26              
27             #-----------------------------------------------------------------------
28             # Define file handlers
29             #-----------------------------------------------------------------------
30              
31             sub passwd {
32             #-------------------------------------------------------------------
33             # Process /etc/passwd file - this function is "an example"
34             #-------------------------------------------------------------------
35 0     0 0   my ($file, $dbg, $size_limit) = @_;
36 0           my %contents;
37 0           my @columns = qw/login passwd uid gid comment home shell/;
38 0 0         open FILE, "<$file" or return(undef);
39 0           while (my $line=) {
40 0           chomp($line);
41 0           my @fields = split(/:/, $line);
42 0           foreach my $idx (1 .. 6) {
43 0           $contents{$fields[0]}{$columns[$idx]} = $fields[$idx];
44             }
45             }
46 0           close(FILE);
47 0           return(\%contents);
48             }
49              
50             #-----------------------------------------------------------------------
51             # Plain Old Documentation
52             #-----------------------------------------------------------------------
53              
54             =head1 NAME
55              
56             Tie::FileSystem::System - Helper functions for reading in and processing
57             of system files in the Tie::FileSystem framework.
58              
59             =head1 SYNOPSIS
60              
61             This module is not used separately from Tie::FileSystem.
62              
63             =head1 DESCRIPTION
64              
65             Tie::FileSystem represents file system as a Perl hash. Each hash key
66             corresponds to name of a directory or a file. For example, for a file
67             "/etc/passwd" it will be $data{'etc'}{'passwd'}. Contents of the file
68             "/etc/passwd" becomes a value corresponding to the
69             $data{'etc'}{'passwd'}.
70              
71             Standard handling procedure for directories is to store a listing of
72             files in the directory as keys. Standard procedure for files is to store
73             a contents of the file in the scalar value.
74              
75             For certain files with known structure it is possible to define
76             subroutines for special handling. Tie::FileSystem::System" defines
77             subroutines for handling system files and, for starters, has 'passwd'
78             handling subroutine. "/etc/passwd" can be represented asa hash with
79             following structure: $data{'etc'}{'passwd'}{$username}{$field}.
80              
81             =head1 USING THE MODULE
82              
83             This modules is used internally by Tie::FileSystem.
84              
85             =head1 BUGS
86              
87             None known.
88              
89             =head1 AUTHOR
90              
91             Vadim V. Kouevda, initdotd@gmail.com
92              
93             =head1 LICENSE and COPYRIGHT
94              
95             Copyright (c) 2003-2007, Vadim V. Kouevda, "KAITS, Inc."
96              
97             This library is free software; you may redistribute it and/or modify it
98             under the same terms as Perl itself.
99              
100             These terms are your choice of any of (1) the Perl Artistic Licence, or
101             (2) version 2 of the GNU General Public License as published by the
102             Free Software Foundation, or (3) any later version of the GNU General
103             Public License.
104              
105             This library is distributed in the hope that it will be useful, but
106             WITHOUT ANY WARRANTY; without even the implied warranty of
107             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
108             General Public License for more details.
109              
110             You should have received a copy of the GNU General Public License along
111             with this library program; it should be in the file COPYING. If not,
112             write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
113             Boston, MA 02111 USA
114              
115             For licensing inquiries, contact the author at initdotd@gmail.com
116              
117             =head1 WARRANTY
118              
119             Module comes with ABSOLUTELY NO WARRANTY. For details, see the license.
120              
121             =head1 AVAILABILITY
122              
123             The latest version can be obtained from CPAN
124              
125             =head1 SEE ALSO
126              
127             Tie::FileSystem(3)
128              
129             =cut
130              
131             #-----------------------------------------------------------------------
132             # $Id: System.pm,v 2.13 2007/03/21 00:11:01 vadim Exp $
133             #-----------------------------------------------------------------------
134             # $Log: System.pm,v $
135             # Revision 2.13 2007/03/21 00:11:01 vadim
136             # Cleaning POD from KA::Tie::Dir references
137             #
138             # Revision 2.11 2007/03/20 21:17:08 vadim
139             # Convert to Tie:FileSystem name space
140             #-----------------------------------------------------------------------
141             1;