NAME

Module::Faker::Dist - a fake CPAN distribution

VERSION

version 0.025

SYNOPSIS

Building one dist at a time makes plenty of sense, so Module::Faker::Dist makes it easy. Building dists from definitions in files is also useful for doing things in bulk (see CPAN::Faker), so there are a bunch of ways to build dists from a definition in a file.

    # Build from a META.yml or META.json file, or the delightful
    # AUTHOR_Foo-Bar-1.234.tar.gz.dist file, which can be zero bytes and gets
    # all the relevant data from the filename.
    my $dist = Module::Faker::Dist->from_file($filename);

META files can contain a key called X_Module_Faker that contains attributes to use in constructing the dist. dist files can contain anything you want, but the contents won't do a thing.

You can use the new method on Module::Faker::Dist, of course, but it's a bit of a pain. You might, instead, want to use from_struct, which is very close to new, but with more sugar.

PERL VERSION

This module should work on any version of perl still receiving updates from the Perl 5 Porters. This means it should work on any version of perl released in the last two to three years. (That is, if the most recently released version is v5.40, then this module should work on both v5.40 and v5.38.)

Although it may work on older versions of perl, no guarantee is made that the minimum required version will not be increased. The version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl.

ATTRIBUTES

name

This is the name of the dist. It will usually look like Foo-Bar.

version

This is the version of the dist, usually some kind of versiony string like 1.234 or maybe 1.2.3.

abstract

The abstract! This is a short, pithy description of the distribution, usually less than a sentence.

release_status

This is the dist's release status. (See CPAN::Meta::Spec.) It defaults to stable but unstable and testing are valid values.

cpan_author

This is the PAUSE id of the author, like RJBS.

archive_ext

This is the extension of the archive to build, when you build an archive. This defaults to tar.gz. zip should work, but right now it doesn't. So probably stuck to tar.gz. It would be cool to support more attributes in the future.

append

This is an arrayref of hashrefs, each of which looks like:

  { file => $filename, content => $character_string }

The content will be UTF-8 encoded and put into a file with the given name.

This feature is a bit weird. Maybe it will go away eventually.

mtime

If given, this is the epoch seconds to which to set the mtime of the generated file. This is useful in rare occasions.

x_authority

This is the X_Authority header that gets put into the META files.

license

This is the meta spec license string for the distribution. It defaults to perl_5.

authors

This is an array of strings who are used as the authors in the dist metadata. The default is:

  [ "AUTHOR <AUTHOR@cpan.local>" ]

...where AUTHOR is the cpan_author of the dist.

include_provides_in_meta

This is a bool. If true, the produced META files will include a provides key based on the packages in the dist. It defaults to false, to match the most common behavior of dists in the wild.

provides

This is a hashref that gets used as the provides in the metadata.

If no provided, it is built from the packages provided in construction.

If no packages were provided, for a dist named Foo-Bar, it defaults to:

  { 'Foo::Bar' => { version => $DIST_VERSION, file => "lib/Foo/Bar.pm" } }

archive_basename

If written to disk, the archive will be written to...

  $dist->archive_basename . '.' . $dist->archive_ext

The default is:

  $dist->name . '.' . ($dist->version // 'undef')

omitted_files

If given, this is an arrayref of filenames that shouldn't be automatically generated and included.

packages

This is an array of Module::Faker::Package objects. It's built by provides if needed, but you might want to look at using the "from_struct" method to set it up.

more_metadata

This can be given as a hashref of data to merge into the CPAN::Meta files.

meta_munger

If given, this is a coderef that's called just before the CPAN::Meta data for the dist is written to disk, an can be used to change things, especially into invalid data. It is expected to return the new content to serialize.

It's called like this:

  $coderef->($struct, { format => $format, version => $version });

...where $struct is the result of $cpan_meta->as_struct. $version is the version number of the target metafile. Normally, both version 1.4 and 2 are requested. $format is either yaml or json.

If the munger returns a string instead of a structure, it will be used as the content of the file being written. This lets you put all kinds of nonsense in those meta files. Have fun, go nuts!

METHODS

modules

This produces and returns a list of Module::Faker::Module objects, representing modules. Modules, if you're not as steeped in CPAN toolchain nonsense, are the .pm files in which packages are defined.

These are produced by combining the packages from "packages" into files based on their in_file attributes.

make_dist_dir

  my $directory_name = $dist->make_dist_dir(\%arg);

This returns the name of a directory into which the dist's contents have been written. If a dir argument is provided, the dist will be written to a directory beneath that dir. Otherwise, it will be written below a temporary directory.

make_archive

  my $archive_filename = $dist->make_archive(\%arg);

This writes the dist archive file, like a tarball or zip file. If a dir argument is given, it will be written in that directory. Otherwise, it will be written to a temporary directory. If the author_prefix argument is given and true, it will be written under a hashed author dir, like:

  U/US/USERID/Foo-Bar-1.23.tar.gz

from_file

  my $dist = Module::Faker::Dist->from_file($filename);

Given a filename with dist configuration, this builds the dist described by the file.

Given a file ending in yaml or yml or json, it's treated as a CPAN::Meta file and interpreted as such. The key X_Module_Faker can be present to provide attributes that don't match data found in a meta file.

Given a file ending in dist, all the configuration comes from the filename, which should look like this:

  AUTHOR_Dist-Name-1.234.tar.gz.dist

from_struct

  my $dist = Module::Faker::Dist->from_struct(\%arg);

This is sugar over new, working like this:

  • packages version defaults to the dist version unless specified

  • packages for dist Foo-Bar defaults to Foo::Bar unless specified

  • if specified, packages is an optlist

AUTHOR

Ricardo Signes <cpan@semiotic.systems>

COPYRIGHT AND LICENSE

This software is copyright (c) 2008 by Ricardo Signes.

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