File Coverage

blib/lib/System/Timeout.pm
Criterion Covered Total %
statement 19 21 90.4
branch 4 6 66.6
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 29 35 82.8


line stmt bran cond sub pod time code
1             package System::Timeout;
2 1     1   26114 use strict;
  1         2  
  1         47  
3 1     1   6 use warnings;
  1         2  
  1         37  
4 1     1   5 use vars qw(@ISA @EXPORT_OK $VERSION);
  1         6  
  1         78  
5 1     1   1282 use IPC::Cmd qw(run);
  1         98781  
  1         197  
6              
7             require Exporter;
8             @ISA = qw(Exporter);
9             @EXPORT_OK = qw(system timeout);
10              
11             our $VERSION = '0.07';
12              
13             sub system
14             {
15 2     2 0 1492 return timeout(@_);
16             }
17              
18             sub timeout
19             {
20 4 50   4 0 3210 if ($_[0] !~ /^\d+$/)
21             {
22 0         0 my $r = CORE::system(@_);
23 0         0 return $r;
24             }
25             else
26             {
27 4         15 my $timeout_secs = shift @_;
28 4         20 my $ref_cmd = \@_;
29 4         31 my $r = run(command => $ref_cmd, timeout=> $timeout_secs, verbose=>1, );
30 4 100       8047077 return 0 if $r;
31 2 50       54 return 1 unless $r;
32             }
33             }
34              
35             1;
36              
37             __END__