1 package Git::SVN::GlobSpec;
6 my ($class, $glob, $pattern_ok) = @_;
8 $re =~ s!/+$!!g; # no need for trailing slashes
9 my (@left, @right, @patterns);
11 my $die_msg = "Only one set of wildcards " .
12 "(e.g. '*' or '*/*/*') is supported: $glob\n";
13 for my $part (split(m|/|, $glob)) {
14 if ($pattern_ok && $part =~ /[{}]/ &&
15 $part !~ /^\{[^{}]+\}/) {
16 die "Invalid pattern in '$glob': $part\n";
18 my $nstars = $part =~ tr/*//;
20 die "Only one '*' is allowed in a pattern: '$part'\n";
22 if ($part =~ /(.*)\*(.*)/) {
23 die $die_msg if $state eq "right";
24 my ($l, $r) = ($1, $2);
26 my $pat = quotemeta($l) . '[^/]*' . quotemeta($r);
27 push(@patterns, $pat);
28 } elsif ($pattern_ok && $part =~ /^\{(.*)\}$/) {
29 die $die_msg if $state eq "right";
31 my $p = quotemeta($1);
33 push(@patterns, "(?:$p)");
35 if ($state eq "left") {
43 my $depth = @patterns;
45 die "One '*' is needed in glob: '$glob'\n";
47 my $left = join('/', @left);
48 my $right = join('/', @right);
49 $re = join('/', @patterns);
51 grep(length, quotemeta($left),
54 my $left_re = qr/^\/\Q$left\E(\/|$)/;
55 bless { left => $left, right => $right, left_regex => $left_re,
56 regex => qr/$re/, glob => $glob, depth => $depth }, $class;
60 my ($self, $path) = @_;
61 return (length $self->{left} ? "$self->{left}/" : '') .
62 $path . (length $self->{right} ? "/$self->{right}" : '');