File Coverage

lib/Devel/Trepan/Condition.pm
Criterion Covered Total %
statement 21 23 91.3
branch 4 6 66.6
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 30 35 85.7


line stmt bran cond sub pod time code
1             # -*- coding: utf-8 -*-
2             # Copyright (C) 2011 Rocky Bernstein <rocky@cpan.org>
3             # NOTE: this does syntax checking and has problems on MS Windows.
4             # More specific context checking can be had in DB::Eval::eval_not_ok()
5             # and that is gnereally (I think) we will be using.
6 19     19   57009 use strict; use warnings;
  19     19   43  
  19         546  
  19         106  
  19         38  
  19         711  
7             package Devel::Trepan::Condition;
8 19     19   116 use English qw( -no_match_vars );
  19         41  
  19         98  
9 19     19   5780 use vars qw(@EXPORT @ISA);
  19         39  
  19         5144  
10             @EXPORT = qw( is_valid_condition );
11             @ISA = qw(Exporter);
12              
13             sub is_valid_condition($) {
14 27     27 0 24496 my ($expr) = @_;
15 27 50       184 return 1 if ($OSNAME eq 'MSWin32');
16 27         13837 my $pid = fork();
17 27 100       873 if ($pid) {
18 21         3852013 waitpid($pid, 0);
19 21         1070 return $CHILD_ERROR == 0;
20             } else {
21 6         454 close STDERR;
22 6 50       362 if ($OSNAME eq 'MSWin32') {
23 0           system ($EXECUTABLE_NAME, '-c', '-e', $expr);
24 0           exit $?;
25             } else {
26 6           exec($EXECUTABLE_NAME, '-c', '-e', $expr);
27             }
28             }
29             }
30              
31             # Demo code
32             unless (caller) {
33             for my $expr ('$a=2', '1+', "join(', ', \@ARGV)", 'join(", ", @ARGV)') {
34             my $ok = is_valid_condition($expr);
35             printf("$expr is %sa valid_condition\n", $ok ? '' : 'not ');
36             }
37             }
38              
39             1;