/[cvs]/nfo/perl/libs/libp.pm
ViewVC logotype

Diff of /nfo/perl/libs/libp.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by cvsjoko, Fri Jul 19 18:13:50 2002 UTC revision 1.8 by joko, Sun Dec 1 22:11:35 2002 UTC
# Line 3  Line 3 
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.8  2002/12/01 22:11:35  joko
7    #  + sub cmd
8    #  + sub run_cmds
9    #
10    #  Revision 1.7  2002/11/29 04:44:53  joko
11    #  - sub array_getRelations
12    #  + sub getNewPerlObjectByPkgName
13    #
14    #  Revision 1.6  2002/11/17 07:18:59  joko
15    #  + sub deep_copy
16    #
17    #  Revision 1.5  2002/10/27 18:34:28  joko
18    #  + sub now
19    #
20    #  Revision 1.4  2002/08/16 19:06:39  cvsjoko
21    #  + sub getDirList
22    #
23  #  Revision 1.3  2002/07/19 18:13:50  cvsjoko  #  Revision 1.3  2002/07/19 18:13:50  cvsjoko
24  #  no message  #  no message
25  #  #
# Line 17  Line 34 
34    
35  package libp;  package libp;
36    
37    use strict;
38    use warnings;
39    
40  require Exporter;  require Exporter;
41  @ISA = qw( Exporter );  our @ISA = qw( Exporter );
42  @EXPORT = qw(  our @EXPORT_OK = qw(
43      Dumper      Dumper
44      md5 md5_hex md5_base64      md5 md5_hex md5_base64
45      ParseDate UnixDate      ParseDate UnixDate
# Line 27  require Exporter; Line 47  require Exporter;
47      stripHtml stripSpaces stripNewLines toReal trim      stripHtml stripSpaces stripNewLines toReal trim
48      croak      croak
49      array_getDifference      array_getDifference
50        getDirList
51        now
52        deep_copy
53        getNewPerlObjectByPkgName
54        cmd
55        run_cmds
56  );  );
57    
 use strict;  
 use warnings;  
   
58  use Data::Dumper;  use Data::Dumper;
59  use Digest::MD5 qw(md5 md5_hex md5_base64);  use Digest::MD5 qw(md5 md5_hex md5_base64);
60    
# Line 47  use POSIX qw(strftime); Line 70  use POSIX qw(strftime);
70    
71  use Carp;  use Carp;
72    
73    use DirHandle;
74    
75    
76  ########################################  ########################################
77    
# Line 97  sub stripHtml { Line 122  sub stripHtml {
122    return $result;    return $result;
123  }  }
124    
125  sub array_getRelations {  
126    my $a_ref = shift;  
127    my $b_ref = shift;  
128    my @a = @{$a_ref};  # =============================================
129    my @b = @{$b_ref};  # "global" vars used in directory-recursive-parsing
130    my $dirlist_buf;
131    my @isect = my @diff = my @union = ();  my @dirlist_path;
132    my $e;  my $dirlist_base;
133    my %count;  
134      sub entry_callback {
135    foreach $e (@a, @b) { $count{$e}++ }  
136      my $entry = shift;
137    foreach $e (keys %count) {  
138        push(@union, $e);    # CHECKS
139        push @{ $count{$e} == 2 ? \@isect : \@diff }, $e;    # dont't use this:
140      if ($entry eq '.' || $entry eq '..') { return; }
141    
142      # PREPARE
143      # prepare path to current entry
144      my $cur_entry = join('/', @dirlist_path, $entry);
145      # prepare path to current entry (absolute)
146      my $cur_entry_abs = join('/', $dirlist_base, @dirlist_path, $entry);
147    
148      # ENTRY
149      # add current entry to buffer
150      $dirlist_buf .= $cur_entry . "\n";
151    
152      # (SUB-)DIRECTORY
153      # check if current entry is a (sub-)directory ...
154      if (-d $cur_entry_abs) {
155        push @dirlist_path, $cur_entry;
156        # ... and parse this (recursion here!!!)
157        iterate_path($cur_entry_abs);
158        pop @dirlist_path;
159      }
160    }
161    
162    sub iterate_path {
163    
164      my $path = shift;
165    
166      # create new "DirHandle"-object
167      my $d = new DirHandle $path;
168      if (defined $d) {
169    
170        # iterate through all entries in $path ($d->read) and call out entry-handler on each entry
171        while (defined(my $line = $d->read)) {
172          entry_callback($line);
173        }
174    
175        undef $d;
176    }    }
177      }
178    my $result = {  
179      union => \@union,  sub getDirList {
180      isect => \@isect,  
181      diff => \@diff,    $dirlist_base = shift;
182    };  
183      # reset vars
184      $dirlist_buf = '';
185      @dirlist_path = ();
186    
187      # start parsing file-structure
188      iterate_path($dirlist_base);
189    
190      # return complete list of directory-content including files and subdirs
191      # entries are newline (\n) - seperated
192      return $dirlist_buf;
193    
194  }  }
195    # =============================================
196    
197    
198  sub array_getDifference {  sub now {
199    my $res = array_getRelations(shift, shift);    return strftime("%Y-%m-%d %H:%M:%S", localtime);
200    return $res->{diff};  }
201    
202    # ACK's go to ...
203    sub deep_copy {
204      my $this = shift;
205      if (not ref $this) {
206        $this;
207      } elsif (ref $this eq "ARRAY") {
208        [map deep_copy($_), @$this];
209      } elsif (ref $this eq "HASH") {
210        +{map { $_ => deep_copy($this->{$_}) } keys %$this};
211      } elsif (ref $this eq "CODE") {
212        $this;
213      } else { die "what type is $_?" }
214    }
215    
216    sub getNewPerlObjectByPkgName {
217      my $pkgname = shift;
218      my $args = shift;
219      #$logger->debug( __PACKAGE__ . "->getNewPerlObjectByPkgName( pkgname $pkgname args $args )" );
220      my $evstring = "use $pkgname;";
221      eval($evstring);
222      #$@ && $logger->error( __PACKAGE__ . ':' . __LINE__ . " Error in eval $evstring: " .  $@ );
223      $@ && print( __PACKAGE__ . ':' . __LINE__ . " Error in eval \"$evstring\": " .  $@ );
224      return $pkgname->new($args);
225    }
226    
227    sub cmd ($) {
228      my $cmd = shift;
229      $cmd = 'perl ' . $cmd;
230      my $sep = "-" x 90;
231      print $sep, "\n";
232      print "  ", $cmd, "\n";
233      print $sep, "\n";
234      system($cmd);
235      print "\n";
236    }
237    
238    sub run_cmds {
239      foreach (@_) {
240        cmd($_);
241      }
242  }  }
243    
244  1;  1;

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.8

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