The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

CPANPLUS::Dist::Debora::Util - Utility functions

VERSION

version 0.012

SYNOPSIS

  use CPANPLUS::Dist::Debora::Util qw(
      parse_version
      module_is_distributed_with_perl
      decode_utf8
      slurp_utf8
      spew_utf8
      can_run
      run
      find_most_recent_mtime
      find_shared_objects
  );

  my $name    = 'Module::CoreList';
  my $version = parse_version('2.32');
  my $ok      = module_is_distributed_with_perl($name, $version);

  my $string = decode_utf8($bytes);
  my $ok     = spew_utf8($filename, $string);
  my $string = slurp_utf8($filename);

  my $program = can_run('perl');
  if ($program) {
      my $output = '';
      if (run(command => [$program, '-v'], buffer => \$output)) {
          print $output;
      }
  }

  my $last_modification = find_most_recent_mtime($sourcedir);
  for my $filename (@{find_shared_objects($stagingdir)}) {
    say $filename;
  }

DESCRIPTION

This module provides utility functions for CPANPLUS::Dist::Debora.

SUBROUTINES/METHODS

parse_version

  my $version = parse_version($string);

Returns a version object.

module_is_distributed_with_perl

  my $is_included = module_is_distributed_with_perl($name, $version);

Checks whether the specified module is part of the standard Perl distribution.

decode_utf8

  my $string = decode_utf8($bytes);

Decodes UTF-8 encoded bytes to a string.

slurp_utf8

  my $string = slurp_utf8($filename);

Reads UTF-8 encoded data from a file.

spew_utf8

  my $ok = spew_utf8($filename, $string);

Writes a string to a file.

can_run

  my $path = can_run($program);

Locates an external command and returns the path to the binary or the undefined value.

run

  my $ok = run(
      command  => [$program, @args],
      dir      => $dir,
      buffer   => \$bytes,
      verbose  => 0|1,
      on_error => sub { say "Could not run '$_[0]': $_[1]" },
  );

Runs an external command in the current or specified directory. Optionally stores the command output in a variable.

unix_path

  my $path = unix_path($path);

Converts an OS specific path into a Unix path with forward slashes.

filetype

  my $type = filetype($filename);

Determines a file's type. Returns "data", "executable", "script" or "text";

find_most_recent_mtime

  my $mtime = find_most_recent_mtime($sourcedir);

Searches the specified directory recursively for the last modified file. Returns the modification time.

find_shared_objects

  my @filenames = @{find_shared_objects($stagingdir)};

Searches the specified directory recursively for shared objects and executable programs.

is_testing

  my $is_testing = is_testing;

Returns true if automated or release testing is enabled.

DIAGNOSTICS

Could not run 'COMMAND'

An external command could not be run.

CONFIGURATION AND ENVIRONMENT

Environment variables

AUTOMATED_TESTING, RELEASE_TESTING

The test mode is enabled if any of these variables is set. No packages are installed in test mode.

DEPENDENCIES

Requires only modules that are distributed with Perl.

INCOMPATIBILITIES

None.

BUGS AND LIMITATIONS

Install IPC::Run if IPC::Open3 causes IO::Select to output warnings.

AUTHOR

Andreas Vögele <voegelas@cpan.org>

LICENSE AND COPYRIGHT

Copyright (C) 2023 Andreas Vögele

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.