| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | package Vi::QuickFix; | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 17 | ▶ | use 5.008_000; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 17 | ▶ | use strict; use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | # use Carp; | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | our $VERSION; | |||||||||||||||||||||||||||||||||||||||||
| 8 | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||
| 9 | 16 | ▶ | $VERSION = ('$Revision: 1.134 $' =~ /(\d+.\d+)/)[ 0]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | unless ( caller ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | # process <> if called as an executable | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | exec_mode(1); # signal fact ( to END processing) | |||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | require Getopt::Std; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | Getopt::Std::getopts( 'q:f:v', \ my %opt); | |||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | print "$0 version $VERSION\n" and exit 0 if $opt{ v}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$opt{'v'} && (print("$0 version $Vi::QuickFix::VERSION\n") && exit 0)
print "$0 version $Vi::QuickFix::VERSION\n" and exit 0
MC/DC0%0/2
$opt{'v'} && (print("$0 version $Vi::QuickFix::VERSION\n") && exit 0)
$opt{'v'}
print "$0 version $Vi::QuickFix::VERSION\n"
Truth table0%0/3
A && B
A= $opt{'v'}B= print "$0 version $Vi::QuickFix::VERSION\n"
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | err_open( $opt{ q} || $opt{ f}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$opt{'q'} || $opt{'f'}
MC/DC0%0/2
$opt{'q'} || $opt{'f'}
$opt{'q'}
$opt{'f'}
Truth table0%0/3
A || B
A= $opt{'q'}B= $opt{'f'}
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | print && err_out( $_) while <>; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | exit; | |||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | ########################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | # keywords for ->import | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 11 | ▶ | use constant KEYWORDS => qw(silent sig tie fork); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | # environment variable(s) | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 11 | ▶ | use constant VAR_SOURCEFILE => 'VI_QUICKFIX_SOURCEFILE'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | BEGIN {{ # space for private variables | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 11 | my $relay = ''; # method of transfer to error file: "sig" or "tie" | |||||||||||||||||||||||||||||||||||||||||
| 34 | 11 | my %invocation; # from where was import() called? | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | sub import { | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 8 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=12 SCAR=25.3
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 8 | my %keywords; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 8 | @keywords{ KEYWORDS()} = (); | |||||||||||||||||||||||||||||||||||||||||
| 40 | 8 | ▶ | $keywords{ shift()} = 1 while @_ and exists $keywords{ $_[ 0]}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ and exists $keywords{$_[0]}
MC/DC100%2/2
@_ and exists $keywords{$_[0]}
@_
exists $keywords{$_[0]}
Truth table100%3/3
A and B
A= @_B= exists $keywords{$_[0]}
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 8 | my $filename = shift; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 8 | ▶ | make_silent() if $keywords{ silent}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 8 | my ( $wanted_relay) = grep $keywords{ $_}, qw( sig tie fork); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 8 | ▶ | $relay = $wanted_relay || default_relay(); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$wanted_relay || default_relay()
MC/DC0%0/2
$wanted_relay || default_relay()
$wanted_relay
default_relay()
Truth table66%2/3
A || B
A= $wanted_relayB= default_relay()
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 8 | ▶ | if ( my $reason = relay_obstacle( $relay) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | croak( "Cannot use '$relay' method: $reason"); | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 7 | ▶ | err_open($filename) unless $relay eq 'fork'; # happens in background | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 6 | ▶ | if ( $relay eq 'tie' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | # if tied, it's tied to ourselves (otherwise obstacle) | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 4 | ▶ | tie *STDERR, 'Vi::QuickFix::Tee', '>&STDERR' unless tied *STDERR; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | } elsif ( $relay eq 'sig' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | $SIG{ $_} = Vi::QuickFix::SigHandler->new( $_) for | |||||||||||||||||||||||||||||||||||||||||
| 55 | qw( __WARN__ __DIE__); | ||||||||||||||||||||||||||||||||||||||||||
| 56 | } elsif ( $relay eq 'fork' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | *STDERR = fork_relay($filename); | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | # save invocation for obligate message | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 6 | (undef, @invocation{qw(file line)}) = caller; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | # internal variables | ||||||||||||||||||||||||||||||||||||||||||
| 64 | { | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 11 | my $exec_mode; # set if lib file is run as a script | |||||||||||||||||||||||||||||||||||||||||
| 66 | sub exec_mode { | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 16 | ▶ | $exec_mode = shift if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exec_mode: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 16 | $exec_mode; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 11 | my $silent = 0; # switch off otherwise obligatory warning | |||||||||||||||||||||||||||||||||||||||||
| 72 | 12 | ▶ | sub make_silent { $silent = 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_silent: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 18 | ▶ | sub is_silent { $silent } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_silent: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 11 | my $errfile = 'errors.err'; # name of error file | |||||||||||||||||||||||||||||||||||||||||
| 76 | 11 | my $errhandle; # write formatted errors here | |||||||||||||||||||||||||||||||||||||||||
| 77 | # open the given file (or default), set $errfile and $errhandle | ||||||||||||||||||||||||||||||||||||||||||
| 78 | sub err_open { | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 12 | ▶ | $errfile = shift || 'errors.err'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
err_open: called CC=4 SCAR=13.9
Pod
undocumented
Condition100%2/2
shift() || 'errors.err'
MC/DC100%1/1
shift() || 'errors.err'
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 12 | ▶ | $errhandle = IO::File->new( $errfile, '>') or warn( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | "Can't create error file '$errfile': $!" | ||||||||||||||||||||||||||||||||||||||||||
| 82 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 11 | ▶ | $errhandle->autoflush if $errhandle; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | sub err_print { | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 20 | ▶ | print $errhandle @_ if $errhandle; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
err_print: called CC=2 SCAR=7.6
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | sub err_clean { | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 11 | ▶ | my $unlink = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
err_clean: called CC=5 SCAR=16.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 11 | ▶ | close $errhandle if $errhandle; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 11 | ▶ | unlink $errfile if $errfile and $unlink and not -s $errfile; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$errfile and $unlink and not -s $errfile
$errfile and $unlink
MC/DC33%1/3
$errfile and $unlink and not -s $errfile
$errfile
$unlink
not -s $errfile
Truth table50%2/4
A and B and not(C)
A= $errfileB= $unlinkC= not -s $errfile
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 11 | sub err_out { | |||||||||||||||||||||||||||||||||||||||||
| 98 | # handle multiple, possibly multi-line messages (though usually | ||||||||||||||||||||||||||||||||||||||||||
| 99 | # there will be only one) | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 32 | ▶ | for ( map split( /\n+/), @_ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
err_out: called CC=9 SCAR=25.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 32 | my $out; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 32 | ▶ | if ( /.+:\d+:/ ) { # already in QuickFix format, pass on | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | err_print("$_\n"); | |||||||||||||||||||||||||||||||||||||||||
| 104 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 32 | for ( parse_perl_msg($_) ) { | |||||||||||||||||||||||||||||||||||||||||
| 106 | 20 | ▶ | my ( $message, $file, $line, $rest) = @$_ or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 20 | ▶ | $message .= $rest if $rest =~ s/^,//; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 20 | ▶ | $file eq '-' and defined and $file = $_ for | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$file eq "-" and defined $_
MC/DC0%0/2
$file eq "-" and defined $_
$file eq "-"
defined $_
Truth table33%1/3
A and B
A= $file eq "-"B= defined $_
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | $ENV{ VAR_SOURCEFILE()}; | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 20 | err_print("$file:$line:$message\n"); | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | # use constant PERL_MSG => qr/^(.*?) at (.*?) line (\d+)(\.?|,.*)$/; | ||||||||||||||||||||||||||||||||||||||||||
| 117 | sub parse_perl_msg { | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 32 | ▶ | my @coll; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_perl_msg: called CC=6 SCAR=18.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 32 | for ( shift ) { | |||||||||||||||||||||||||||||||||||||||||
| 120 | 32 | ▶ | while ( m/ at /g ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 20 | my $text = substr($_, 0, $-[0]); | |||||||||||||||||||||||||||||||||||||||||
| 122 | 20 | my $pos = pos; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 20 | ▶ | while ( m/ line (\d+)(\.?|,.*)$/g ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 20 | my $file = substr($_, $pos, $-[0] - $pos); | |||||||||||||||||||||||||||||||||||||||||
| 125 | 20 | my $line = $1; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 20 | my $rest = $2; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 20 | push @coll, [$text, $file, $line, $rest]; | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 20 | pos = $pos; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 32 | ▶ | return @coll if @coll <= 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my @existing = grep -e $_->[1], @coll; | |||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | return @existing if @existing; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | return @coll; | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | # issue warning, erase error file | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 11 | my $end_entiteled = $$; | |||||||||||||||||||||||||||||||||||||||||
| 140 | END { | ||||||||||||||||||||||||||||||||||||||||||
| 141 | # issue warning (only original process, and not in exec mode) | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 11 | ▶ | unless ( is_silent or exec_mode() or $$ != $end_entiteled ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
END: called CC=8 SCAR=20.8
Branch: 1 branch
Condition100%6/6
is_silent() or exec_mode() or $$ != $end_entiteled
is_silent() or exec_mode()
MC/DC66%2/3
is_silent() or exec_mode() or $$ != $end_entiteled
is_silent()
exec_mode()
$$ != $end_entiteled
Truth table75%3/4
A or B or C
A= is_silent()B= exec_mode()C= $$ != $end_entiteled
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 4 | my $invocation_at = "at $invocation{file} line $invocation{line}"; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 4 | warn "QuickFix ($relay) active $invocation_at\n"; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | # silently remove objects | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 11 | make_silent(); | |||||||||||||||||||||||||||||||||||||||||
| 148 | 11 | ▶ | if ( $relay eq 'tie' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 3 | untie *STDERR; | |||||||||||||||||||||||||||||||||||||||||
| 150 | } elsif ( $relay eq 'sig' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 2 | $SIG{ $_} = 'DEFAULT' for qw( __WARN__ __DIE__); | |||||||||||||||||||||||||||||||||||||||||
| 152 | } elsif ( $relay eq 'fork' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | close STDERR; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | wait_kid(); | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | # remove file if created by us and empty | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 11 | err_clean($$ == $end_entiteled); | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 11 | ▶ | }} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 11 | ▶ | use constant MINVERS => 5.008001; # minimum perl version for tie method | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | sub relay_obstacle { | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 10 | ▶ | my $relay = shift || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
relay_obstacle: called CC=6 SCAR=18.5
Pod
undocumented
Condition50%1/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 10 | ▶ | return '' unless $relay eq 'tie'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 8 | ▶ | if ( $] < MINVERS ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | return "perl version is $], must be >= @{[ MINVERS]}"; | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 8 | ▶ | if ( my $tie_ob = tied *STDERR ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 2 | my $tieclass = ref $tie_ob; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 2 | ▶ | return "STDERR already tied to '$tieclass'" unless | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | $tieclass eq 'Vi::QuickFix::Tee'; | ||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 7 | return ''; | |||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 2 | ▶ | sub default_relay { relay_obstacle( 'tie') ? 'sig' : 'tie' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_relay: called CC=2 SCAR=7.6
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | { | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 11 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 5 | my ($read, $write, $kid); | |||||||||||||||||||||||||||||||||||||||||
| 182 | sub fork_relay { | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | my $filename = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fork_relay: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | my $parent = $$; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | pipe $read, $write; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | if ( $kid = fork ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | # parent | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | close $read; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | return $write; | |||||||||||||||||||||||||||||||||||||||||
| 190 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | Carp::croak "Can't fork: $!" unless defined $kid; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | # kid | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | close $write; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | err_open($filename); | |||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | while ( <$read> ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | print STDERR $_; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | err_out($_); | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | err_clean(1); | |||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | exit; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 11 | ▶ | use POSIX ":sys_wait_h"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | sub wait_kid { | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | my $x; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wait_kid: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | do { $x = waitpid -1, WNOHANG } while $x > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | # common destructor method | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 5 | package Vi::QuickFix::Destructor; | |||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 11 | ▶ | use Carp qw( shortmess); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 11 | ▶ | BEGIN { our @CARP_NOT = qw( Vi::QuickFix) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 7 | ▶ | my $ob = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=3 SCAR=16.7
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 7 | ▶ | return if Vi::QuickFix::is_silent or $^C; # it's a mess under -c | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
Vi::QuickFix::is_silent() or $^C
MC/DC0%0/2
Vi::QuickFix::is_silent() or $^C
Vi::QuickFix::is_silent()
$^C
Truth table33%1/3
A or B
A= Vi::QuickFix::is_silent()B= $^C
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | my $id = $ob->id; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | my $msg = shortmess( "QuickFix $id processing interrupted"); | |||||||||||||||||||||||||||||||||||||||||
| 221 | # simulate intact QuickFix processing | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | Vi::QuickFix::err_out( $msg); | |||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | warn "$msg"; | |||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | # Class to associate a DESTROY method with sig handlers | ||||||||||||||||||||||||||||||||||||||||||
| 227 | package Vi::QuickFix::SigHandler; | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 11 | ▶ | use base qw( Vi::QuickFix::Destructor); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | # return a chaining handler for __WARN__ or __DIE__ | ||||||||||||||||||||||||||||||||||||||||||
| 231 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 4 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.5
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 4 | my $sig = shift; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 4 | my $prev_handler = $SIG{ $sig}; | |||||||||||||||||||||||||||||||||||||||||
| 235 | my $sub = sub { | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 6 | ▶ | return $sig unless @_; # backdoor | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=26.5
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 6 | ▶ | Vi::QuickFix::err_out( @_) unless $sig eq '__DIE__' and _in_eval(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$sig eq "__DIE__" and _in_eval()
MC/DC0%0/2
$sig eq "__DIE__" and _in_eval()
$sig eq "__DIE__"
_in_eval()
Truth table33%1/3
A and B
A= $sig eq "__DIE__"B= _in_eval()
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 6 | my $code; | |||||||||||||||||||||||||||||||||||||||||
| 239 | # resolve string at call time | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 6 | ▶ | if ( $prev_handler ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | $code = ref $prev_handler ? | ||||||||||||||||||||||||||||||||||||||||||
| 242 | $prev_handler : | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | \ &{ 'main::' . $prev_handler}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 6 | ▶ | goto &$code if $code; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 6 | ▶ | die @_ if $sig eq '__DIE__'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 6 | warn @_; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 4 | bless $sub, $class; # so we can have a destructor | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | sub _in_eval { | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | my $i = -1; # first call with 0 | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_in_eval: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | while ( defined(my $sub = (caller ++ $i)[3]) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | return 1 if $sub =~ /^\(eval/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | sub id { | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | my $handler = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
id: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | $handler->(); # call without args returns __WARN__ or __DIE__ | |||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | # tie class to tee re-formatted output to an error file | ||||||||||||||||||||||||||||||||||||||||||
| 266 | package Vi::QuickFix::Tee; | ||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | 11 | ▶ | use IO::File; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 11 | ▶ | use Tie::Handle; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 11 | ▶ | use base qw( Tie::StdHandle Vi::QuickFix::Destructor); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | sub WRITE { | ||||||||||||||||||||||||||||||||||||||||||
| 273 | 10 | ▶ | my $fh = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
WRITE: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 10 | my ( $scalar, $length) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 10 | Vi::QuickFix::err_out( $scalar); | |||||||||||||||||||||||||||||||||||||||||
| 276 | 10 | $fh->Tie::StdHandle::WRITE( @_); | |||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | sub id { 'STDERR' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
id: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | __END__ | ||||||||||||||||||||||||||||||||||||||||||