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

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

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