/[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.4 by cvsjoko, Fri Aug 16 19:06:39 2002 UTC revision 1.13 by joko, Mon Dec 23 04:25:13 2002 UTC
# Line 3  Line 3 
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.13  2002/12/23 04:25:13  joko
7    #  + sub bool2status
8    #
9    #  Revision 1.12  2002/12/22 14:15:02  joko
10    #  + sub mkObject
11    #
12    #  Revision 1.11  2002/12/19 16:27:17  joko
13    #  +- renamed 'cmd' to 'run_cmd'
14    #
15    #  Revision 1.10  2002/12/19 01:05:35  joko
16    #  + sub today
17    #
18    #  Revision 1.9  2002/12/05 13:54:00  joko
19    #  + fix: let 'deep_copy' print its message out (instead of die)
20    #
21    #  Revision 1.8  2002/12/01 22:11:35  joko
22    #  + sub cmd
23    #  + sub run_cmds
24    #
25    #  Revision 1.7  2002/11/29 04:44:53  joko
26    #  - sub array_getRelations
27    #  + sub getNewPerlObjectByPkgName
28    #
29    #  Revision 1.6  2002/11/17 07:18:59  joko
30    #  + sub deep_copy
31    #
32    #  Revision 1.5  2002/10/27 18:34:28  joko
33    #  + sub now
34    #
35  #  Revision 1.4  2002/08/16 19:06:39  cvsjoko  #  Revision 1.4  2002/08/16 19:06:39  cvsjoko
36  #  + sub getDirList  #  + sub getDirList
37  #  #
# Line 20  Line 49 
49    
50  package libp;  package libp;
51    
52    use strict;
53    use warnings;
54    
55  require Exporter;  require Exporter;
56  @ISA = qw( Exporter );  our @ISA = qw( Exporter );
57  @EXPORT = qw(  our @EXPORT_OK = qw(
58      Dumper      Dumper
59      md5 md5_hex md5_base64      md5 md5_hex md5_base64
60      ParseDate UnixDate      ParseDate UnixDate
61      strftime      strftime
     stripHtml stripSpaces stripNewLines toReal trim  
62      croak      croak
63    
64        stripHtml stripSpaces stripNewLines toReal trim
65      array_getDifference      array_getDifference
66      getDirList      getDirList
67        now today
68        deep_copy
69        getNewPerlObjectByPkgName
70        run_cmd run_cmds
71        mkObject
72        bool2status
73  );  );
74    
 use strict;  
 use warnings;  
   
75  use Data::Dumper;  use Data::Dumper;
76  use Digest::MD5 qw(md5 md5_hex md5_base64);  use Digest::MD5 qw(md5 md5_hex md5_base64);
77    
# Line 103  sub stripHtml { Line 139  sub stripHtml {
139    return $result;    return $result;
140  }  }
141    
 sub array_getRelations {  
   my $a_ref = shift;  
   my $b_ref = shift;  
   my @a = @{$a_ref};  
   my @b = @{$b_ref};  
   
   my @isect = my @diff = my @union = ();  
   my $e;  
   my %count;  
     
   foreach $e (@a, @b) { $count{$e}++ }  
   
   foreach $e (keys %count) {  
       push(@union, $e);  
       push @{ $count{$e} == 2 ? \@isect : \@diff }, $e;  
   }  
     
   my $result = {  
     union => \@union,  
     isect => \@isect,  
     diff => \@diff,  
   };  
142    
 }  
   
 sub array_getDifference {  
   my $res = array_getRelations(shift, shift);  
   return $res->{diff};  
 }  
143    
144    
145  # =============================================  # =============================================
# Line 204  sub getDirList { Line 212  sub getDirList {
212  # =============================================  # =============================================
213    
214    
215    sub now {
216      return strftime("%Y-%m-%d %H:%M:%S", localtime);
217    }
218    
219    sub today {
220      return strftime("%Y-%m-%d", localtime);
221    }
222    
223    # ACK's go to ...
224    sub deep_copy {
225      my $this = shift;
226      if (not ref $this) {
227        $this;
228      } elsif (ref $this eq "ARRAY") {
229        [map deep_copy($_), @$this];
230      } elsif (ref $this eq "HASH") {
231        +{map { $_ => deep_copy($this->{$_}) } keys %$this};
232      } elsif (ref $this eq "CODE") {
233        $this;
234      #} else { die "deep_copy asks: what type is $this?" }
235      } else { print "deep_copy asks: what type is $this?", "\n"; }
236    }
237    
238    sub getNewPerlObjectByPkgName {
239      my $pkgname = shift;
240      my $args = shift;
241      #$logger->debug( __PACKAGE__ . "->getNewPerlObjectByPkgName( pkgname $pkgname args $args )" );
242      my $evstring = "use $pkgname;";
243      eval($evstring);
244      #$@ && $logger->error( __PACKAGE__ . ':' . __LINE__ . " Error in eval $evstring: " .  $@ );
245      $@ && print( __PACKAGE__ . ':' . __LINE__ . " Error in eval \"$evstring\": " .  $@ );
246      return $pkgname->new($args);
247    }
248    
249    sub mkObject {
250      my $pkgname = shift;
251      #my $args = shift;
252      #$logger->debug( __PACKAGE__ . "->getNewPerlObjectByPkgName( pkgname $pkgname args $args )" );
253      my $evstring = "use $pkgname;";
254      eval($evstring);
255      #$@ && $logger->error( __PACKAGE__ . ':' . __LINE__ . " Error in eval $evstring: " .  $@ );
256      $@ && print( __PACKAGE__ . ':' . __LINE__ . " Error in eval \"$evstring\": " .  $@ );
257      return $pkgname->new(@_);
258    }
259    
260    sub run_cmd {
261      my $cmd = shift;
262      $cmd = 'perl ' . $cmd;
263      my $sep = "-" x 90;
264      print $sep, "\n";
265      print "  ", $cmd, "\n";
266      print $sep, "\n";
267      system($cmd);
268      print "\n";
269    }
270    
271    sub run_cmds {
272      foreach (@_) {
273        run_cmd($_);
274      }
275    }
276    
277    sub bool2status {
278      my $bool = shift;
279      return ($bool ? 'ok' : 'failed');
280    }
281    
282  1;  1;

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.13

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