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

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

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