| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package IPC::PrettyPipe::Stream::Utils; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | # ABSTRACT: support utilities for streams | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 19 |  |  | 19 |  | 231564 | use strict; | 
|  | 19 |  |  |  |  | 49 |  | 
|  | 19 |  |  |  |  | 591 |  | 
| 6 | 19 |  |  | 19 |  | 115 | use warnings; | 
|  | 19 |  |  |  |  | 42 |  | 
|  | 19 |  |  |  |  | 846 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | our $VERSION = '0.13'; | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 19 |  |  | 19 |  | 8754 | use parent 'Exporter'; | 
|  | 19 |  |  |  |  | 5791 |  | 
|  | 19 |  |  |  |  | 120 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | our @EXPORT_OK = qw[ parse_spec ]; | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | sub parse_spec { | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 229 |  |  | 229 | 1 | 38938 | 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 | 100 |  |  |  | 1788 | unless $op =~ /^(?: | 
| 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 | 19 |  |  | 19 |  | 13721 | my %opc = map { $_ => $+{$_} } grep { exists $+{$_} } qw[ N M Op ]; | 
|  | 19 |  |  |  |  | 7733 |  | 
|  | 19 |  |  |  |  | 3419 |  | 
|  | 96 |  |  |  |  | 300 |  | 
|  | 161 |  |  |  |  | 1049 |  | 
|  | 288 |  |  |  |  | 1623 |  | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | ( $opc{type} ) | 
| 72 | 96 |  |  |  |  | 312 | = grep { defined $+{$_} } qw[ redirect redirect_stdout_stderr close dup ]; | 
|  | 384 |  |  |  |  | 1581 |  | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | # fill in default value for N for stdin & stdout | 
| 75 |  |  |  |  |  |  | $opc{N} = substr( $opc{Op}, 0, 1 ) eq '<' ? 0 : 1 | 
| 76 | 96 | 100 | 100 |  |  | 825 | if $+{redirect} && !defined $opc{N}; | 
|  |  | 100 |  |  |  |  |  | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | $opc{param}++ | 
| 79 | 96 | 100 | 100 |  |  | 656 | if $+{redirect} || $+{redirect_stdout_stderr}; | 
| 80 |  |  |  |  |  |  |  | 
| 81 | 96 |  |  |  |  | 356 | return \%opc; | 
| 82 |  |  |  |  |  |  | } | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | 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__ |