| 1 | package IPC::PrettyPipe::Stream::Utils; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: support utilities for streams | ||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | 24 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 24 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 24 | our $VERSION = '0.13'; | |||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 24 | ▶ | use parent 'Exporter'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 24 | our @EXPORT_OK = qw[ parse_spec ]; | |||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 229 | ▶ | sub parse_spec { | ||||||||||||||||||||||||||||||
|
Subroutine
parse_spec: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 229 | my $op = shift; | |||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | # parse stream operator; shell syntax (similarity to IPC::Run's | ||||||||||||||||||||||||||||||||
| 20 | # syntax is no coincidence) | ||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | # for consistency, N is always the descriptor which needs to | ||||||||||||||||||||||||||||||||
| 23 | # be opened or dup'ed to. M is never touched. | ||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | return {} | ||||||||||||||||||||||||||||||||
| 26 | 229 | ▶ | unless $op =~ /^(?: | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 27 | # <, N< | ||||||||||||||||||||||||||||||||
| 28 | # >, N> | ||||||||||||||||||||||||||||||||
| 29 | # >>, N>> | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | (?'redirect' | ||||||||||||||||||||||||||||||||
| 32 | (?'N' \d+ (?!<<) )? # don't match N<< | ||||||||||||||||||||||||||||||||
| 33 | (?'Op' | ||||||||||||||||||||||||||||||||
| 34 | (?: [<>]{1,2} ) | ||||||||||||||||||||||||||||||||
| 35 | ) | ||||||||||||||||||||||||||||||||
| 36 | ) | ||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | # >&, &> | ||||||||||||||||||||||||||||||||
| 39 | | (?'redirect_stdout_stderr' | ||||||||||||||||||||||||||||||||
| 40 | (?'Op' >& | &> ) | ||||||||||||||||||||||||||||||||
| 41 | ) | ||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | # N<&- | ||||||||||||||||||||||||||||||||
| 44 | | (?'close' | ||||||||||||||||||||||||||||||||
| 45 | (?'N' \d+ ) | ||||||||||||||||||||||||||||||||
| 46 | (?'Op' <& ) | ||||||||||||||||||||||||||||||||
| 47 | (?'M' - ) | ||||||||||||||||||||||||||||||||
| 48 | ) | ||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | # M<&N | ||||||||||||||||||||||||||||||||
| 51 | | (?'dup' | ||||||||||||||||||||||||||||||||
| 52 | (?'M' \d+ ) | ||||||||||||||||||||||||||||||||
| 53 | (?'Op' <& ) | ||||||||||||||||||||||||||||||||
| 54 | (?'N' \d+ ) | ||||||||||||||||||||||||||||||||
| 55 | ) | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | # N>&M | ||||||||||||||||||||||||||||||||
| 58 | | (?'dup' | ||||||||||||||||||||||||||||||||
| 59 | (?'N' \d+ ) | ||||||||||||||||||||||||||||||||
| 60 | (?'Op' >& ) | ||||||||||||||||||||||||||||||||
| 61 | (?'M' \d+ ) | ||||||||||||||||||||||||||||||||
| 62 | ) | ||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | )$/x | ||||||||||||||||||||||||||||||||
| 65 | ; | ||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | # force a copy of the hash; it's magical and a simple return | ||||||||||||||||||||||||||||||||
| 68 | # of the elements doesn't work. | ||||||||||||||||||||||||||||||||
| 69 | 96 | my %opc = map { $_ => $+{$_} } grep { exists $+{$_} } qw[ N M Op ]; | |||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | ( $opc{type} ) | ||||||||||||||||||||||||||||||||
| 72 | 96 | = grep { defined $+{$_} } qw[ redirect redirect_stdout_stderr close dup ]; | |||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | # fill in default value for N for stdin & stdout | ||||||||||||||||||||||||||||||||
| 75 | $opc{N} = substr( $opc{Op}, 0, 1 ) eq '<' ? 0 : 1 | ||||||||||||||||||||||||||||||||
| 76 | 96 | ▶ | if $+{redirect} && !defined $opc{N}; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$+{"redirect"} and not defined $opc{"N"}
MC/DC100%2/2
$+{"redirect"} and not defined $opc{"N"}
$+{"redirect"}
not defined $opc{"N"}
Truth table100%3/3
A and not(B)
A= $+{"redirect"}B= not defined $opc{"N"}
| |||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | $opc{param}++ | ||||||||||||||||||||||||||||||||
| 79 | 96 | ▶ | if $+{redirect} || $+{redirect_stdout_stderr}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$+{"redirect"} or $+{"redirect_stdout_stderr"}
MC/DC100%2/2
$+{"redirect"} or $+{"redirect_stdout_stderr"}
$+{"redirect"}
$+{"redirect_stdout_stderr"}
Truth table100%3/3
A or B
A= $+{"redirect"}B= $+{"redirect_stdout_stderr"}
| |||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | 96 | return \%opc; | |||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | 24 | 1; | |||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | # | ||||||||||||||||||||||||||||||||
| 87 | # This file is part of IPC-PrettyPipe | ||||||||||||||||||||||||||||||||
| 88 | # | ||||||||||||||||||||||||||||||||
| 89 | # This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory. | ||||||||||||||||||||||||||||||||
| 90 | # | ||||||||||||||||||||||||||||||||
| 91 | # This is free software, licensed under: | ||||||||||||||||||||||||||||||||
| 92 | # | ||||||||||||||||||||||||||||||||
| 93 | # The GNU General Public License, Version 3, June 2007 | ||||||||||||||||||||||||||||||||
| 94 | # | ||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | __END__ | ||||||||||||||||||||||||||||||||