Blame SOURCES/perl.prov.stack

d5f2d8
#!/usr/bin/perl
d5f2d8
d5f2d8
# This is free software.  You may redistribute copies of it under the terms of
d5f2d8
# the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
d5f2d8
# There is NO WARRANTY, to the extent permitted by law.
d5f2d8
d5f2d8
# This script was originally written by Ken Estes Mail.com
d5f2d8
# kestes@staff.mail.com
d5f2d8
d5f2d8
# a simple script to print the proper name for Perl libraries.
d5f2d8
d5f2d8
# It does not parse the perl grammar but instead just lex it looking for
d5f2d8
# what we want. It takes special care to ignore comments and pod's.
d5f2d8
d5f2d8
# The filenames to scan are either passed on the command line or if
d5f2d8
# that is empty they are passed via stdin.
d5f2d8
d5f2d8
# If there are lines in the file which match the pattern
d5f2d8
#      (m/^\s*\$VERSION\s*=\s+/)
d5f2d8
# then these are taken to be the version numbers of the modules.
d5f2d8
# Special care is taken with a few known idioms for specifying version
d5f2d8
# numbers of files under rcs/cvs control.
d5f2d8
d5f2d8
# If there are strings in the file which match the pattern
d5f2d8
#     m/^\s*\$RPM_Provides\s*=\s*["'](.*)['"]/i
d5f2d8
# then these are treated as additional names which are provided by the
d5f2d8
# file and are printed as well.
d5f2d8
d5f2d8
my $perl_prov ="__SCL_NAME__";
d5f2d8
d5f2d8
if ("@ARGV") {
d5f2d8
  foreach (@ARGV) {
d5f2d8
    process_file($_);
d5f2d8
  }
d5f2d8
} else {
d5f2d8
d5f2d8
  # notice we are passed a list of filenames NOT as common in unix the
d5f2d8
  # contents of the file.
d5f2d8
d5f2d8
  foreach (<>) {
d5f2d8
    process_file($_);
d5f2d8
  }
d5f2d8
}
d5f2d8
d5f2d8
d5f2d8
foreach $module (sort keys %require) {
d5f2d8
  if (length($require{$module}) == 0) {
d5f2d8
    print "$perl_prov($module)\n";
d5f2d8
  } else {
d5f2d8
d5f2d8
    # I am not using rpm3.0 so I do not want spaces around my
d5f2d8
    # operators. Also I will need to change the processing of the
d5f2d8
    # $RPM_* variable when I upgrade.
d5f2d8
d5f2d8
    print "$perl_prov($module) = $require{$module}\n";
d5f2d8
  }
d5f2d8
}
d5f2d8
d5f2d8
exit 0;
d5f2d8
d5f2d8
d5f2d8
d5f2d8
sub process_file {
d5f2d8
d5f2d8
  my ($file) = @_;
d5f2d8
  chomp $file;
d5f2d8
d5f2d8
  if (!open(FILE, $file)) {
d5f2d8
    warn("$0: Warning: Could not open file '$file' for reading: $!\n");
d5f2d8
    return;
d5f2d8
  }
d5f2d8
d5f2d8
  my ($package, $version, $incomment, $inover) = ();
d5f2d8
d5f2d8
  while (<FILE>) {
d5f2d8
d5f2d8
    # skip the documentation
d5f2d8
d5f2d8
    # we should not need to have item in this if statement (it
d5f2d8
    # properly belongs in the over/back section) but people do not
d5f2d8
    # read the perldoc.
d5f2d8
d5f2d8
    if (m/^=(head[1-4]|pod|for|item)/) {
d5f2d8
      $incomment = 1;
d5f2d8
    }
d5f2d8
d5f2d8
    if (m/^=(cut)/) {
d5f2d8
      $incomment = 0;
d5f2d8
      $inover = 0;
d5f2d8
    }
d5f2d8
d5f2d8
    if (m/^=(over)/) {
d5f2d8
      $inover = 1;
d5f2d8
    }
d5f2d8
d5f2d8
    if (m/^=(back)/) {
d5f2d8
      $inover = 0;
d5f2d8
    }
d5f2d8
d5f2d8
    if ($incomment || $inover) {
d5f2d8
      next;
d5f2d8
    }
d5f2d8
d5f2d8
    # skip the data section
d5f2d8
    if (m/^__(DATA|END)__$/) {
d5f2d8
      last;
d5f2d8
    }
d5f2d8
d5f2d8
    # not everyone puts the package name of the file as the first
d5f2d8
    # package name so we report all namespaces except some common
d5f2d8
    # false positives as if they were provided packages (really ugly).
d5f2d8
d5f2d8
    if (m/^\s*package\s+([_:a-zA-Z0-9]+)\s*v?([0-9._]+)?\s*;/) {
d5f2d8
      $package = $1;
d5f2d8
      $version = defined($2) ? $2 : undef;
d5f2d8
      if ($package eq 'main') {
d5f2d8
        undef $package;
d5f2d8
        undef $version;
d5f2d8
      } else {
d5f2d8
        # If $package already exists in the $require hash, it means
d5f2d8
        # the package definition is broken up over multiple blocks.
d5f2d8
        # In that case, don't stomp a previous $VERSION we might have
d5f2d8
        # found.  (See BZ#214496.)
d5f2d8
        $require{$package} = $version unless (exists $require{$package});
d5f2d8
      }
d5f2d8
    }
d5f2d8
d5f2d8
    # after we found the package name take the first assignment to
d5f2d8
    # $VERSION as the version number. Exporter requires that the
d5f2d8
    # variable be called VERSION so we are safe.
d5f2d8
d5f2d8
    # here are examples of VERSION lines from the perl distribution
d5f2d8
d5f2d8
    #FindBin.pm:$VERSION = $VERSION = sprintf("%d.%02d", q$Revision: 1.9 $ =~ /(\d+)\.(\d+)/);
d5f2d8
    #ExtUtils/Install.pm:$VERSION = substr q$Revision: 1.9 $, 10;
d5f2d8
    #CGI/Apache.pm:$VERSION = (qw$Revision: 1.9 $)[1];
d5f2d8
    #DynaLoader.pm:$VERSION = $VERSION = "1.03";     # avoid typo warning
d5f2d8
    #General.pm:$Config::General::VERSION = 2.33;
d5f2d8
    #
d5f2d8
    # or with the new "our" pragma you could (read will) see:
d5f2d8
    #
d5f2d8
    #    our $VERSION = '1.00'
d5f2d8
    if ($package && m/^\s*(our\s+)?\$(\Q$package\E::)?VERSION\s*=[^=~>]\s*/) {
d5f2d8
d5f2d8
      # first see if the version string contains the string
d5f2d8
      # '$Revision' this often causes bizarre strings and is the most
d5f2d8
      # common method of non static numbering.
d5f2d8
d5f2d8
      if (m/\$Revision: (\d+[.0-9]+)/) {
d5f2d8
        $version = $1;
d5f2d8
      } elsif (m/\b['"]?v?(\d+(?:\.[.0-9]+)?)(_\d*|[a-zA-Z]*)?['"]?\b/) {
d5f2d8
d5f2d8
        # look for a static number hard coded in the script
d5f2d8
d5f2d8
        $version = $1;
d5f2d8
      }
d5f2d8
      $require{$package} = $version;
d5f2d8
    }
d5f2d8
d5f2d8
    # Allow someone to have a variable that defines virtual packages
d5f2d8
    # The variable is called $RPM_Provides.  It must be scoped with
d5f2d8
    # "our", but not "local" or "my" (just would not make sense).
d5f2d8
    #
d5f2d8
    # For instance:
d5f2d8
    #
d5f2d8
    #     $RPM_Provides = "blah bleah"
d5f2d8
    #
d5f2d8
    # Will generate provides for "blah" and "bleah".
d5f2d8
    #
d5f2d8
    # Each keyword can appear multiple times.  Don't
d5f2d8
    #  bother with datastructures to store these strings,
d5f2d8
    #  if we need to print it print it now.
d5f2d8
d5f2d8
    if (m/^\s*(our\s+)?\$RPM_Provides\s*=\s*["'](.*)['"]/i) {
d5f2d8
      foreach $_ (split(/\s+/, $2)) {
d5f2d8
        print "$_\n";
d5f2d8
      }
d5f2d8
    }
d5f2d8
d5f2d8
  }
d5f2d8
d5f2d8
  close(FILE) ||
d5f2d8
    die("$0: Could not close file: '$file' : $!\n");
d5f2d8
d5f2d8
  return;
d5f2d8
}