NAME
PPM::Make::Util - Utility functions for PPM::Make
SYNOPSIS
use PPM::Make 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;
- html_escape
-
Escapes &, >, <, and ".
my $escaped = html_escape('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;
- 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);
- version
-
Makes an attempt to extract the file and version number of a CPAN distribution file (eg, packagename and 1.23 from packagename-1.23.tar.gz).
my $dist = 'package-1.23.tar.gz'; my ($file, $version) = version($dist);
- which
-
Find the full path to a program, if available.
my $perl = which('perl');
- parse_ppd
-
Parse a ppd file.
my $ppd = 'package.ppd'; my $d = parse_ppd($ppd); print $d->{ABSTRACT}; print $d->{OS}->{NAME};
- 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;
- dist_search
-
Uses CPAN.pm to perform a distribution search.
my $dist = 'libnet'; my $results = dist_search($dist);
A case-insensitive search can be made by giving
dist_search
an argument of <no_case => 1>, while partial matches can be made by specifying <partial => 1>. The results are returned as a hash reference of the formforeach my $dist (keys %{$results}) { print "Distribution: $dist\n"; print "Version: $results->{$dist}->{version}\n"; print "Description: $results->{$dist}->{abstract}\n"; print "Author: $results->{$dist}->{author}\n"; print "CPAN file: $results->{$dist}->{cpan_file}\n"; }
Not all fields are guaranteed to have a value.
- mod_search
-
Uses CPAN.pm to perform a module search.
my $mod = 'Net::FTP'; my $results = mod_search($mod);
A case-insensitive search can be made by giving
mod_search
an argument of <no_case => 1>, while partial matches can be made by specifying <partial => 1>. The results are returned as a hash reference of the formforeach my $mod (keys %{$results}) { print "Module: $mod\n"; print "Version: $results->{$mod}->{version}\n"; print "Description: $results->{$mod}->{abstract}\n"; print "Author: $results->{$mod}->{author}\n"; print "CPAN file: $results->{$mod}->{cpan_file}\n"; }
Not all fields are guaranteed to have a value.
- ppm_search
-
Uses PPM.pm to perform a distribution search.
my $dist = 'libnet'; my $results = ppm_search($dist);
A case-insensitive search can be made by giving
ppm_search
an argument ofno_case => 1
, while partial matches can be made by specifyingpartial => 1
. An author or abstract query can be specified withAUTHOR => 1
andABSTRACT => 1
, respectively. The search can be restricted to a given repository by specifying the URL aslocation => $url
; otherwise, a search of all available respositories is made. The results are returned as a hash reference of the formforeach my $package (keys %{$results}) { print "Package: $package\n"; print "Version: $results->{$package}->{version}\n"; print "Author: $results->{$package}->{author}\n"; print "Abstract: $results->{$package}->{abstract}\n"; print "Location(s): @{$results->{$package}->{repository}}\n"; }
Not all fields are guaranteed to have a value.
- 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 has an extension \.(tar\.gz|tgz|tar\.Z|zip), 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 a module name, and fetch the corresponding CPAN distribution, if found.
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();
- module_status
-
Checks the status of a module Foo::Bar against a supplied version:
my ($module, $wanted_version) = ('Foo::Bar', 1.23); my $status = module_status($module, $wanted_version);
The returned value of
$recommendation
will be 1 if the module is present and it's version is greater than or equal to the desired version. A return value of 0 means the module is present, but it's version is less than the wanted version. If the module is not present, a value of -1 is returned.$wanted_version
can be undefined, which is interpreted to mean any version of the module is OK. - package_status
-
Checks the status of a PPM package Foo-Bar:
my ($pack, $wanted_version) = ('Foo-Bar', '1,2,3,4'); my $status = package_status($pack, $wanted_version);
The returned value of
$recommendation
will be 1 if the package is present and it's version is greater than or equal to the desired version. A return value of 0 means the package is present, but it's version is less than the wanted version. If the package is not present, a value of -1 is returned.$wanted_version
can be undefined, which is interpreted to mean any version of the package is OK. - have_module
-
Checks to see if a module Foo::Bar is already installed:
my $module = "Foo::Bar"; my ($present, $version) = have_module($module);
If not present,
$present
will be undefined. Note that even if the module is present,$version
may be undefined. - parse_version
-
Extracts a version string from a module file.
my $version = parse_version('C:/Perl/lib/CPAN.pm');
- have_package
-
Checks to see if a PPM package Foo-Bar is already installed:
my $pack = "Foo-Bar"; my ($present, $version) = have_package($pack);
If not present,
$present
will be undefined. Note that$version
, being the ppd version string, is expected always to be defined. - vcmp_ppd
-
Compares two ppd version strings ($s1, $s2), and returns 1 if $s1 > $s2, 0 if $s1 == $s2, and -1 if $s1 < $s2.
my $s1 = '1,2,3,4'; # the installed version my $s2 = '2,3,4,5'; # a potential upgrade my $cmp = vcmp_ppd($s1, $s2);
- vcmp_cpan
-
Compares two CPAN version strings ($s1, $s2), and returns 1 if $s1 > $s2, 0 if $s1 == $s2, and -1 if $s1 < $s2.
my $s1 = '1.23'; # the installed version my $s2 = '4.56'; # a potential upgrade my $cmp = vcmp_cpan($s1, $s2);
- fetch_nmake
-
Fetch
nmake.exe
.unless (my $installed_nmake = fetch_nmake) { print "I could not retrieve nmake"; }
COPYRIGHT
This program is copyright, 2003, by Randy Kobes <randy@theoryx5.uwinnipeg.ca>. It is distributed under the same terms as Perl itself.
SEE ALSO
PPM.