blib/lib/Devel/Trepan/Condition.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 45 CC 4 SCAR 24.0
CC
4
Cov
0%
is_valid_condition
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 11.0
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 use strict; use warnings;
7 package Devel::Trepan::Condition;
8 use English qw( -no_match_vars );
9 use vars qw(@EXPORT @ISA);
10 @EXPORT = qw( is_valid_condition );
11 @ISA = qw(Exporter);
12  
13 sub is_valid_condition($) {
14 my ($expr) = @_;
15 return 1 if ($OSNAME eq 'MSWin32');
16 my $pid = fork();
17 if ($pid) {
18 waitpid($pid, 0);
19 return $CHILD_ERROR == 0;
20 } else {
21 close STDERR;
22 if ($OSNAME eq 'MSWin32') {
23 system ($EXECUTABLE_NAME, '-c', '-e', $expr);
24 exit $?;
25 } else {
26 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;