/[cvs]/nfo/perl/libs/Data/Storage/Handler/Directory.pm
ViewVC logotype

Annotation of /nfo/perl/libs/Data/Storage/Handler/Directory.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Sun Jan 19 02:11:37 2003 UTC (21 years, 5 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
+ from libp

1 joko 1.1 ## --------------------------------------------------------------------------------
2     ## $Id: Files.pm,v 1.1 2002/12/03 15:52:53 joko Exp $
3     ## --------------------------------------------------------------------------------
4     ## $Log: Files.pm,v $
5     ## --------------------------------------------------------------------------------
6    
7    
8     package Data::Storage::Handler::Directory;
9    
10     use strict;
11     use warnings;
12    
13     use base ("Data::Storage::Handler::Abstract");
14    
15     require Exporter;
16     our @ISA = qw( Exporter );
17     our @EXPORT_OK = qw(
18     getDirList
19     );
20    
21    
22     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - main
23    
24     use DirHandle;
25    
26     use Data::Dumper;
27     #use Data::Storage::Result::Files;
28    
29     # get logger instance
30     my $logger = Log::Dispatch::Config->instance;
31    
32     sub getMetaInfo {
33     my $self = shift;
34     $logger->debug( __PACKAGE__ . "->getMetaInfo()" );
35     return;
36     return {
37     # 'disconnectMethod' => 'disconnect',
38     };
39     }
40    
41    
42    
43     # =============================================
44     # "global" vars used in directory-recursive-parsing
45     my $dirlist_buf;
46     my @dirlist_path;
47     my $dirlist_base;
48    
49    
50     sub entry_callback {
51    
52     my $entry = shift;
53    
54     # CHECKS
55     # dont't use this:
56     if ($entry eq '.' || $entry eq '..') { return; }
57    
58     # PREPARE
59     # prepare path to current entry
60     my $cur_entry = join('/', @dirlist_path, $entry);
61     # prepare path to current entry (absolute)
62     my $cur_entry_abs = join('/', $dirlist_base, @dirlist_path, $entry);
63    
64     # ENTRY
65     # add current entry to buffer
66     $dirlist_buf .= $cur_entry . "\n";
67    
68     # (SUB-)DIRECTORY
69     # check if current entry is a (sub-)directory ...
70     if (-d $cur_entry_abs) {
71     push @dirlist_path, $cur_entry;
72     # ... and parse this (recursion here!!!)
73     iterate_path($cur_entry_abs);
74     pop @dirlist_path;
75     }
76     }
77    
78     sub iterate_path {
79    
80     my $path = shift;
81    
82     # create new "DirHandle"-object
83     my $d = new DirHandle $path;
84     if (defined $d) {
85    
86     # iterate through all entries in $path ($d->read) and call out entry-handler on each entry
87     while (defined(my $line = $d->read)) {
88     entry_callback($line);
89     }
90    
91     undef $d;
92     }
93     }
94    
95     sub getDirList {
96    
97     $dirlist_base = shift;
98    
99     # reset vars
100     $dirlist_buf = '';
101     @dirlist_path = ();
102    
103     # start parsing file-structure
104     iterate_path($dirlist_base);
105    
106     # return complete list of directory-content including files and subdirs
107     # entries are newline (\n) - seperated
108     return $dirlist_buf;
109    
110     }
111    
112     1;

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed