NAME

PPM::Make::Util - Utility functions for PPM::Make

SYNOPSIS

use PPM::Make::Util qw(:all);

DESCRIPTION

This module contains a number of utility functions used by PPM::Make.

fix_path

Ensures a path is a Unix-type path, with no spaces.

my $path = 'C:\Program Files\';
my $unix_version = fix_path($path);
load_cs

Loads a CHECKSUMS file into $cksum (adapted from the MD5 check of CPAN.pm)

my $cksum = load_cs('CHECKSUMS');
verifyMD5

Verify a CHECKSUM for a $file

my $ok = verifyMD5($cksum, $file);
print "$file checked out OK" if $ok;
xml_encode

Escapes &, >, <, and ", as well as high ASCII characters.

my $escaped = xml_encode('Five is > four');
is_core

Tests to see if a module is part of the core, based on whether or not the file is found within a site type of directory.

my $is_core = is_core('Net::FTP');
print "Net::FTP is a core module" if $is_core;
is_ap_core

Tests to see if a package is part of the ActivePerl core (at least for recent ActivePerl versions).

my $is_ap_core = is_ap_core('libwin32');
print "libwin32 is a core package" if $is_ap_core;
trim

Trims white space.

my $string = '    This is a sentence.   ';
my $trimmed = trim($string);
file_to_dist

In scalar context, returns a CPAN distribution name filename based on an input file A/AB/ABC/filename-1.23.tar.gz:

my $file = 'A/AB/ABC/defg-1.23.tar.gz';
my $dist = file_to_dist($file);

In a list context, returns both the distribution name filename and the version number 1.23:

my $file = 'A/AB/ABC/defg-1.23.tar.gz';
my ($dist, $version) = file_to_dist($cpan_file);
ppd2cpan_version

Converts a ppd-type of version string (eg, 1,23,0,0) into a ppd one of the form 1.23:

my $s = "1,23,0,0";
my $v = ppd2cpan_version($v);
cpan2ppd_version

Converts a cpan-type of version string (eg, 1.23) into a ppd one of the form 1,23,0,0:

my $v = 1.23;
my $s = cpan2ppd_version($v);
parse_ppd

Parse a ppd file.

my $ppd = 'package.ppd';
my $d = parse_ppd($ppd);
print $d->{ABSTRACT};
print $d->{OS}->{NAME};

my $e = parse_ppd($ppd, 'MSWin32-x86-multi-thread');
print $e->{ABSTRACT};

This routine takes a required argument of a ppd file and, optionally, an ARCHITECTURE name to restrict the results to. It returns a data structure containing the information of the ppd file:

$d->{SOFTPKG}->{NAME}
$d->{SOFTPKG}->{VERSION}
$d->{TITLE}
$d->{AUTHOR}
$d->{ABSTRACT}
$d->{PROVIDE}
$d->{DEPENDENCY}
$d->{OS}->{NAME}
$d->{ARCHITECTURE}->{NAME}
$d->{CODEBASE}->{HREF}
$d->{INSTALL}->{EXEC}
$d->{INSTALL}->{SCRIPT}
$d->{INSTALL}->{HREF}

The PROVIDE and DEPENDENDENCY tags are array references containing lists of, respectively, the prerequisites required and the modules supplied by the package, with keys of NAME and VERSION.

If there is more than one IMPLEMENTATION section in the ppd file, all the results except for the SOFTPKG elements and TITLE, AUTHOR, and ABSTRACT will be placed in a $d->{IMPLENTATION} array reference. If an optional second argument is passed to parse_ppd($file, $arch), this will filter out all implementation sections except for the specified ARCHITECTURE given by $arch.

src_and_build

Returns the source and build directories used with CPAN.pm, if present. If not, returns those used with PPM, if those are present. If neither of these are available, returns the system temp directory.

my ($src_dir, $build_dir)= src_and_build;
tempfile

Generates the name of a random temporary file.

my $tmpfile = tempfile;
parse_version

Extracts a version string from a module file.

my $version = parse_version('C:/Perl/lib/CPAN.pm');
parse_abstract

Attempt to obtain an abstract from a module file.

my $package = 'CPAN';
my $file = 'C:/Perl/lib/CPAN.pm';
my $abstract = parse_abstract($package, $file);

Uses a remote soap server or CPAN.pm to perform a module search.

my $mod = 'Net::FTP';
my $results = mod_search($mod);

The query term must match exactly, in a case sensitive manner. The results are returned as a hash reference of the form

print <<"END";
  Module: $results->{mod_name}
  Version: $results->{mod_vers}
  Description: $results->{mod_abs}
  Author: $results->{author}
  CPAN file: $results->{dist_file}
  Distribution: $results->{dist_name}
END

Not all fields are guaranteed to have a value.

If an array reference is passed to mod_search containing a list of modules to be queried, a corresponding hash reference is returned, the keys being the query terms and the values being a hash reference as above.

Uses a remote soap server or CPAN.pm to perform a distribution search.

my $dist = 'libnet';
my $results = dist_search($dist);

The query term must match exactly, in a case sensitive manner. The results are returned as a hash reference of the form

print <<"END";
  Distribution: $results->{dist_name}
  Version: $results->{dist_vers}
  Description: $results->{dist_abs}
  Author: $results->{author}
  CPAN file: $results->{dist_file}
END

Not all fields are guaranteed to have a value.

If an array reference is passed to dist_search with a list of distributions to be queried, a corresponding hash reference is returned, the keys being the query terms and the values being a hash reference as above.

cpan_file {

Given a file of the form file.tar.gz and a CPAN id of the form <ABCDEFG>, will return the CPAN file A/AB/ABCDEFG/file.tar.gz.

my $cpanid = 'GBARR';
my $file = 'libnet-1.23.tar.gz';
my $cpan_file = cpan_file($cpanid, $file);
fetch_file

Fetches a file, and if successful, returns the stored filename. If the file is specified beginning with http:// or ftp://:

my $fetch = 'http://my.server/my_file.tar.gz';
my $filename = fetch_file($file);

will grab this file directly. Otherwise, if the file is specified with an absolute path name, has an extension \.(tar\.gz|tgz|tar\.Z|zip), and if the file exists locally, it will use that; otherwise, it will assume this is a CPAN distribution and grab it from a CPAN mirror:

my $dist = 'A/AB/ABC/file.tar.gz';
my $filename = fetch_file($dist);

which assumes the file lives under $CPAN/authors/id/. If neither of the above are satisfied, it will assume this is, first of all, a module name, and if not found, a distribution name, and if found, will fetch the corresponding CPAN distribution.

my $mod = 'Net::FTP';
my $filename = fetch_file($mod);
url_list

Gets a list of CPAN mirrors, incorporating any from CPAN.pm.

my @list = url_list();

COPYRIGHT

This program is copyright, 2003, 2006 by Randy Kobes <r.kobes@uwinnipeg.ca>. It is distributed under the same terms as Perl itself.

SEE ALSO

PPM.