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

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

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

revision 1.6 by joko, Fri Mar 28 06:58:06 2003 UTC revision 1.8 by joko, Fri Apr 4 17:31:59 2003 UTC
# Line 2  Line 2 
2  ##  $Id$  ##  $Id$
3  ## ---------------------------------------------------------------------------  ## ---------------------------------------------------------------------------
4  ##  $Log$  ##  $Log$
5    ##  Revision 1.8  2003/04/04 17:31:59  joko
6    ##  + sub make_guid
7    ##
8    ##  Revision 1.7  2003/03/29 07:24:10  joko
9    ##  enhanced 'run_cmd': now tries to execute program with appropriate application (e.g. 'cmd.exe' or 'perl')
10    ##
11  ##  Revision 1.6  2003/03/28 06:58:06  joko  ##  Revision 1.6  2003/03/28 06:58:06  joko
12  ##  new: 'run_cmd' now asynchronous! (via IPC::Run...)  ##  new: 'run_cmd' now asynchronous! (via IPC::Run...)
13  ##  ##
# Line 36  our @EXPORT_OK = qw( Line 42  our @EXPORT_OK = qw(
42    run_cmd run_cmds    run_cmd run_cmds
43    get_chomped    get_chomped
44    bool2status    bool2status
45      make_guid
46  );  );
47    
48    
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -   main  
   
49  use Data::Dumper;  use Data::Dumper;
50  use POSIX qw( strftime );  use POSIX qw( strftime );
51  #use IPC::Run qw( run timeout );  #use IPC::Run qw( run timeout );
52  use IPC::Run qw( start pump finish timeout ) ;  use IPC::Run qw( start pump finish timeout ) ;
53    use Carp;
54    
55    
56    
57  # $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;  # $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
58  # see "perldoc -f localtime"  # see "perldoc -f localtime"
   
59  sub now {  sub now {
60    my $options = shift;    my $options = shift;
61    my $pattern = "%Y-%m-%d %H:%M:%S";    my $pattern = "%Y-%m-%d %H:%M:%S";
# Line 101  sub run_cmd { Line 108  sub run_cmd {
108      # FIXME: detect type of program and run with proper application/interpreter      # FIXME: detect type of program and run with proper application/interpreter
109      # using IPC::Run we have to dispatch this on our own! *no* os-interaction or interpolation here!      # using IPC::Run we have to dispatch this on our own! *no* os-interaction or interpolation here!
110      # => better use absolute path-names only?!      # => better use absolute path-names only?!
111      $cmd = "perl $cmd";      my $application = '';
112        if (RUNNING_IN_HELL()) {
113          $application = 'cmd.exe /C';
114        }
115        
116        if ($cmd =~ m/\w+\.pl\s*.*/) {
117          $application = 'perl';
118        }
119        
120        $cmd = "$application $cmd" if $application;
121        
122      print "IPC::Run: $cmd", "\n";      print "IPC::Run: $cmd", "\n";
123      #run \@cmd, \$in, \$out, \$err, timeout( 10 ) or die "cat: $?";      #run \@cmd, \$in, \$out, \$err, timeout( 10 ) or die "cat: $?";
124            
# Line 140  sub bool2status { Line 157  sub bool2status {
157    
158  sub RUNNING_IN_HELL () { $^O eq 'MSWin32' }  sub RUNNING_IN_HELL () { $^O eq 'MSWin32' }
159    
160    # create global unique identifers using Data::UUID
161    # if updating this code, please also modify Tangram::Storage::make_guid
162    sub make_guid
163      {
164        my $self = shift;
165    
166        my $guid;
167    
168        # try to use Data::UUID first ...
169        eval("use Data::UUID;");
170        if (!$@) {
171          my $ug = Data::UUID->new();
172          $guid = $ug->create_str();
173          
174        # ... if this fails, try to fallback to Data::UUID::PurePerl instead ...
175        } else {
176          eval("use Data::UUID::PurePerl;");
177          if (!$@) {
178            $guid = Data::UUID::PurePerl::generate_id();
179          } else {
180            croak "couldn't create globally unique identifier";
181          }
182        }
183        
184        return $guid;
185      }
186    
187  1;  1;

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

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