<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package File::Glob;

use strict;
our($VERSION, @ISA, @EXPORT_OK, @EXPORT_FAIL, %EXPORT_TAGS, $DEFAULT_FLAGS);

require XSLoader;

@ISA = qw(Exporter);

# NOTE: The glob() export is only here for compatibility with 5.6.0.
# csh_glob() should not be used directly, unless you know what you're doing.

%EXPORT_TAGS = (
    'glob' =&gt; [ qw(
        GLOB_ABEND
        GLOB_ALPHASORT
        GLOB_ALTDIRFUNC
        GLOB_BRACE
        GLOB_CSH
        GLOB_ERR
        GLOB_ERROR
        GLOB_LIMIT
        GLOB_MARK
        GLOB_NOCASE
        GLOB_NOCHECK
        GLOB_NOMAGIC
        GLOB_NOSORT
        GLOB_NOSPACE
        GLOB_QUOTE
        GLOB_TILDE
        bsd_glob
    ) ],
);
$EXPORT_TAGS{bsd_glob} = [@{$EXPORT_TAGS{glob}}];

@EXPORT_OK   = (@{$EXPORT_TAGS{'glob'}}, 'csh_glob');

$VERSION = '1.33';

sub import {
    require Exporter;
    local $Exporter::ExportLevel = $Exporter::ExportLevel + 1;
    Exporter::import(grep {
        my $passthrough;
        if ($_ eq ':case') {
            $DEFAULT_FLAGS &amp;= ~GLOB_NOCASE()
        }
        elsif ($_ eq ':nocase') {
            $DEFAULT_FLAGS |= GLOB_NOCASE();
        }
        elsif ($_ eq ':globally') {
	    no warnings 'redefine';
	    *CORE::GLOBAL::glob = \&amp;File::Glob::csh_glob;
	}
        elsif ($_ eq ':bsd_glob') {
	    no strict; *{caller."::glob"} = \&amp;bsd_glob_override;
            $passthrough = 1;
	}
	else {
            $passthrough = 1;
        }
        $passthrough;
    } @_);
}

XSLoader::load();

$DEFAULT_FLAGS = GLOB_CSH();
if ($^O =~ /^(?:MSWin32|VMS|os2|dos|riscos)$/) {
    $DEFAULT_FLAGS |= GLOB_NOCASE();
}

1;
__END__

=head1 NAME

File::Glob - Perl extension for BSD glob routine

=head1 SYNOPSIS

  use File::Glob ':bsd_glob';

  @list = bsd_glob('*.[ch]');
  $homedir = bsd_glob('~gnat', GLOB_TILDE | GLOB_ERR);

  if (GLOB_ERROR) {
    # an error occurred reading $homedir
  }

  ## override the core glob (CORE::glob() does this automatically
  ## by default anyway, since v5.6.0)
  use File::Glob ':globally';
  my @sources = &lt;*.{c,h,y}&gt;;

  ## override the core glob, forcing case sensitivity
  use File::Glob qw(:globally :case);
  my @sources = &lt;*.{c,h,y}&gt;;

  ## override the core glob forcing case insensitivity
  use File::Glob qw(:globally :nocase);
  my @sources = &lt;*.{c,h,y}&gt;;

  ## glob on all files in home directory
  use File::Glob ':globally';
  my @sources = &lt;~gnat/*&gt;;

=head1 DESCRIPTION

The glob angle-bracket operator C&lt;&lt; &lt;&gt; &gt;&gt; is a pathname generator that
implements the rules for file name pattern matching used by Unix-like shells
such as the Bourne shell or C shell.

File::Glob::bsd_glob() implements the FreeBSD glob(3) routine, which is
a superset of the POSIX glob() (described in IEEE Std 1003.2 "POSIX.2").
bsd_glob() takes a mandatory C&lt;pattern&gt; argument, and an optional
C&lt;flags&gt; argument, and returns a list of filenames matching the
pattern, with interpretation of the pattern modified by the C&lt;flags&gt;
variable.

Since v5.6.0, Perl's CORE::glob() is implemented in terms of bsd_glob().
Note that they don't share the same prototype--CORE::glob() only accepts
a single argument.  Due to historical reasons, CORE::glob() will also
split its argument on whitespace, treating it as multiple patterns,
whereas bsd_glob() considers them as one pattern.  But see C&lt;:bsd_glob&gt;
under L&lt;/EXPORTS&gt;, below.

=head2 META CHARACTERS

  \       Quote the next metacharacter
  []      Character class
  {}      Multiple pattern
  *       Match any string of characters
  ?       Match any single character
  ~       User name home directory

The metanotation C&lt;a{b,c,d}e&gt; is a shorthand for C&lt;abe ace ade&gt;.  Left to
right order is preserved, with results of matches being sorted separately
at a low level to preserve this order.  As a special case C&lt;{&gt;, C&lt;}&gt;, and
C&lt;{}&gt; are passed undisturbed.

=head2 EXPORTS

See also the L&lt;/POSIX FLAGS&gt; below, which can be exported individually.

=head3 C&lt;:bsd_glob&gt;

The C&lt;:bsd_glob&gt; export tag exports bsd_glob() and the constants listed
below.  It also overrides glob() in the calling package with one that
behaves like bsd_glob() with regard to spaces (the space is treated as part
of a file name), but supports iteration in scalar context; i.e., it
preserves the core function's feature of returning the next item each time
it is called.

=head3 C&lt;:glob&gt;

The C&lt;:glob&gt; tag, now discouraged, is the old version of C&lt;:bsd_glob&gt;.  It
exports the same constants and functions, but its glob() override does not
support iteration; it returns the last file name in scalar context.  That
means this will loop forever:

    use File::Glob ':glob';
    while (my $file = &lt;* copy.txt&gt;) {
	...
    }

=head3 C&lt;bsd_glob&gt;

This function, which is included in the two export tags listed above,
takes one or two arguments.  The first is the glob pattern.  The
second, if given, is a set of flags ORed together.  The available
flags and the default set of flags are listed below under L&lt;/POSIX FLAGS&gt;.

Remember that to use the named constants for flags you must import
them, for example with C&lt;:bsd_glob&gt; described above.  If not imported,
and C&lt;use strict&gt; is not in effect, then the constants will be
treated as bareword strings, which won't do what you what.


=head3 C&lt;:nocase&gt; and C&lt;:case&gt;

These two export tags globally modify the default flags that bsd_glob()
and, except on VMS, Perl's built-in C&lt;glob&gt; operator use.  C&lt;GLOB_NOCASE&gt;
is turned on or off, respectively.

=head3 C&lt;csh_glob&gt;

The csh_glob() function can also be exported, but you should not use it
directly unless you really know what you are doing.  It splits the pattern
into words and feeds each one to bsd_glob().  Perl's own glob() function
uses this internally.

=head2 POSIX FLAGS

If no flags argument is give then C&lt;GLOB_CSH&gt; is set, and on VMS and
Windows systems, C&lt;GLOB_NOCASE&gt; too.  Otherwise the flags to use are
determined solely by the flags argument.  The POSIX defined flags are:

=over 4

=item C&lt;GLOB_ERR&gt;

Force bsd_glob() to return an error when it encounters a directory it
cannot open or read.  Ordinarily bsd_glob() continues to find matches.

=item C&lt;GLOB_LIMIT&gt;

Make bsd_glob() return an error (GLOB_NOSPACE) when the pattern expands
to a size bigger than the system constant C&lt;ARG_MAX&gt; (usually found in
limits.h).  If your system does not define this constant, bsd_glob() uses
C&lt;sysconf(_SC_ARG_MAX)&gt; or C&lt;_POSIX_ARG_MAX&gt; where available (in that
order).  You can inspect these values using the standard C&lt;POSIX&gt;
extension.

=item C&lt;GLOB_MARK&gt;

Each pathname that is a directory that matches the pattern has a slash
appended.

=item C&lt;GLOB_NOCASE&gt;

By default, file names are assumed to be case sensitive; this flag
makes bsd_glob() treat case differences as not significant.

=item C&lt;GLOB_NOCHECK&gt;

If the pattern does not match any pathname, then bsd_glob() returns a list
consisting of only the pattern.  If C&lt;GLOB_QUOTE&gt; is set, its effect
is present in the pattern returned.

=item C&lt;GLOB_NOSORT&gt;

By default, the pathnames are sorted in ascending ASCII order; this
flag prevents that sorting (speeding up bsd_glob()).

=back

The FreeBSD extensions to the POSIX standard are the following flags:

=over 4

=item C&lt;GLOB_BRACE&gt;

Pre-process the string to expand C&lt;{pat,pat,...}&gt; strings like csh(1).
The pattern '{}' is left unexpanded for historical reasons (and csh(1)
does the same thing to ease typing of find(1) patterns).

=item C&lt;GLOB_NOMAGIC&gt;

Same as C&lt;GLOB_NOCHECK&gt; but it only returns the pattern if it does not
contain any of the special characters "*", "?" or "[".  C&lt;NOMAGIC&gt; is
provided to simplify implementing the historic csh(1) globbing
behaviour and should probably not be used anywhere else.

=item C&lt;GLOB_QUOTE&gt;

Use the backslash ('\') character for quoting: every occurrence of a
backslash followed by a character in the pattern is replaced by that
character, avoiding any special interpretation of the character.
(But see below for exceptions on DOSISH systems).

=item C&lt;GLOB_TILDE&gt;

Expand patterns that start with '~' to user name home directories.

=item C&lt;GLOB_CSH&gt;

For convenience, C&lt;GLOB_CSH&gt; is a synonym for
C&lt;GLOB_BRACE | GLOB_NOMAGIC | GLOB_QUOTE | GLOB_TILDE | GLOB_ALPHASORT&gt;.

=back

The POSIX provided C&lt;GLOB_APPEND&gt;, C&lt;GLOB_DOOFFS&gt;, and the FreeBSD
extensions C&lt;GLOB_ALTDIRFUNC&gt;, and C&lt;GLOB_MAGCHAR&gt; flags have not been
implemented in the Perl version because they involve more complex
interaction with the underlying C structures.

The following flag has been added in the Perl implementation for
csh compatibility:

=over 4

=item C&lt;GLOB_ALPHASORT&gt;

If C&lt;GLOB_NOSORT&gt; is not in effect, sort filenames is alphabetical
order (case does not matter) rather than in ASCII order.

=back

=head1 DIAGNOSTICS

bsd_glob() returns a list of matching paths, possibly zero length.  If an
error occurred, &amp;File::Glob::GLOB_ERROR will be non-zero and C&lt;$!&gt; will be
set.  &amp;File::Glob::GLOB_ERROR is guaranteed to be zero if no error occurred,
or one of the following values otherwise:

=over 4

=item C&lt;GLOB_NOSPACE&gt;

An attempt to allocate memory failed.

=item C&lt;GLOB_ABEND&gt;

The glob was stopped because an error was encountered.

=back

In the case where bsd_glob() has found some matching paths, but is
interrupted by an error, it will return a list of filenames B&lt;and&gt;
set &amp;File::Glob::ERROR.

Note that bsd_glob() deviates from POSIX and FreeBSD glob(3) behaviour
by not considering C&lt;ENOENT&gt; and C&lt;ENOTDIR&gt; as errors - bsd_glob() will
continue processing despite those errors, unless the C&lt;GLOB_ERR&gt; flag is
set.

Be aware that all filenames returned from File::Glob are tainted.

=head1 NOTES

=over 4

=item *

If you want to use multiple patterns, e.g. C&lt;bsd_glob("a* b*")&gt;, you should
probably throw them in a set as in C&lt;bsd_glob("{a*,b*}")&gt;.  This is because
the argument to bsd_glob() isn't subjected to parsing by the C shell.
Remember that you can use a backslash to escape things.

=item *

On DOSISH systems, backslash is a valid directory separator character.
In this case, use of backslash as a quoting character (via GLOB_QUOTE)
interferes with the use of backslash as a directory separator.  The
best (simplest, most portable) solution is to use forward slashes for
directory separators, and backslashes for quoting.  However, this does
not match "normal practice" on these systems.  As a concession to user
expectation, therefore, backslashes (under GLOB_QUOTE) only quote the
glob metacharacters '[', ']', '{', '}', '-', '~', and backslash itself.
All other backslashes are passed through unchanged.

=item *

Win32 users should use the real slash.  If you really want to use
backslashes, consider using Sarathy's File::DosGlob, which comes with
the standard Perl distribution.

=back

=head1 SEE ALSO

L&lt;perlfunc/glob&gt;, glob(3)

=head1 AUTHOR

The Perl interface was written by Nathan Torkington E&lt;lt&gt;gnat@frii.comE&lt;gt&gt;,
and is released under the artistic license.  Further modifications were
made by Greg Bacon E&lt;lt&gt;gbacon@cs.uah.eduE&lt;gt&gt;, Gurusamy Sarathy
E&lt;lt&gt;gsar@activestate.comE&lt;gt&gt;, and Thomas Wegner
E&lt;lt&gt;wegner_thomas@yahoo.comE&lt;gt&gt;.  The C glob code has the
following copyright:

Copyright (c) 1989, 1993 The Regents of the University of California.
All rights reserved.

This code is derived from software contributed to Berkeley by
Guido van Rossum.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

=over 4

=item 1.

Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

=item 2.

Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

=item 3.

Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

=back

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

=cut
</pre></body></html>