File: Base.pm

package info (click to toggle)
libmakefile-dom-perl 0.004-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 616 kB
  • ctags: 535
  • sloc: perl: 6,552; makefile: 2
file content (52 lines) | stat: -rw-r--r-- 1,170 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#: facilities used by script/sh and also shared by the testers

package Test::Util::Base;

use Spiffy -Base;
use Text::Balanced qw( gen_delimited_pat );

our @EXPORT = qw(
    split_arg process_escape
);

our $DelimPat;

BEGIN {
    $DelimPat = gen_delimited_pat(q{"});
}

sub extract_many (@) {
    my $text = shift;
    my @flds;
    while (1) {
        #warn '@flds = ', Dumper(@flds);
        if ($text =~ /\G\s* ( ; | >>? | < | \|\| | \&\& ) /gcox) {
            push @flds, $1;
        } elsif ($text =~ /\G\s* ( (?:\\.)+ [^'";><\|\&\s]* )/gcox) {
            push @flds, $1;
        } elsif ($text =~ /\G\s*('[^']*')/gco) {
            push @flds, $1;
        } elsif ($text =~ /\G\s*($DelimPat)/gco) {
            push @flds, $1;
        } elsif ($text =~ /\G\s*( \S (?:[^ ; > < ' " \s \\ \| \& ]|\\.)* )/gcox) {
            push @flds, $1;
        } else {
            last;
        }
    }
    return @flds;
}

sub split_arg ($) {
    my $text = shift;
    return () if not defined $text;
    return extract_many($text);
}

sub process_escape (@) {
    return if $_[0] !~ /\\/;
    my $list = quotemeta $_[1];
    $_[0] =~ s/\\[$list]/substr($&,1,1)/eg;
}

1;