Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / TAP / Parser / Utils.pm
CommitLineData
3fea05b9 1package TAP::Parser::Utils;
2
3use strict;
4use Exporter;
5use vars qw($VERSION @ISA @EXPORT_OK);
6
7@ISA = qw( Exporter );
8@EXPORT_OK = qw( split_shell );
9
10=head1 NAME
11
12TAP::Parser::Utils - Internal TAP::Parser utilities
13
14=head1 VERSION
15
16Version 3.17
17
18=cut
19
20$VERSION = '3.17';
21
22=head1 SYNOPSIS
23
24 use TAP::Parser::Utils qw( split_shell )
25 my @switches = split_shell( $arg );
26
27=head1 DESCRIPTION
28
29B<FOR INTERNAL USE ONLY!>
30
31=head2 INTERFACE
32
33=head3 C<split_shell>
34
35Shell style argument parsing. Handles backslash escaping, single and
36double quoted strings but not shell substitutions.
37
38Pass one or more strings containing shell escaped arguments. The return
39value is an array of arguments parsed from the input strings according
40to (approximate) shell parsing rules. It's legal to pass C<undef> in
41which case an empty array will be returned. That makes it possible to
42
43 my @args = split_shell( $ENV{SOME_ENV_VAR} );
44
45without worrying about whether the environment variable exists.
46
47This is used to split HARNESS_PERL_ARGS into individual switches.
48
49=cut
50
51sub split_shell {
52 my @parts = ();
53
54 for my $switch ( grep defined && length, @_ ) {
55 push @parts, $1 while $switch =~ /
56 (
57 (?: [^\\"'\s]+
58 | \\.
59 | " (?: \\. | [^"] )* "
60 | ' (?: \\. | [^'] )* '
61 )+
62 ) /xg;
63 }
64
65 for (@parts) {
66 s/ \\(.) | ['"] /defined $1 ? $1 : ''/exg;
67 }
68
69 return @parts;
70}
71
721;