NAME
DistGen - Creates simple distributions for testing.
SYNOPSIS
use DistGen;
my $dist = DistGen->new(dir => $tmp);
...
$dist->add_file('t/some_test.t', $contents);
...
$dist->regen;
chdir($dist->dirname) or
die "Cannot chdir to '@{[$dist->dirname]}': $!";
...
$dist->clean;
...
chdir($cwd) or die "cannot return to $cwd";
$dist->remove;
API
Constructor
new()
Create a new object. Does not write its contents (see "regen()".)
my $tmp = MBTest->tmpdir;
my $dist = DistGen->new(
name => 'Foo::Bar',
dir => $tmp,
xs => 1,
);
The parameters are as follows.
- name
-
The name of the module this distribution represents. The default is 'Simple'. This should be a "Foo::Bar" (module) name, not a "Foo-Bar" dist name.
- dir
-
The (parent) directory in which to create the distribution directory. The default is File::Spec->curdir. The distribution will be created under this according to the "dist" form of
name(e.g. "Foo-Bar".) - xs
-
If true, generates an XS based module.
Manipulating the Distribution
These methods immediately affect the filesystem.
regen()
Regenerate all missing or changed files.
$dist->regen(clean => 1);
If the optional clean argument is given, it also removes any extraneous files that do not belong to the distribution.
chdir_in
Change directory into the dist root.
$dist->chdir_in;
chdir_original
Returns to whatever directory you were in before chdir_in() (regardless of the cwd.)
$dist->chdir_original;
clean()
Removes any files that are not part of the distribution.
$dist->clean;
remove()
Removes the entire distribution directory.
Editing Files
Note that $filename should always be specified with unix-style paths, and are relative to the distribution root directory. Eg 'lib/Module.pm'
No filesystem action is performed until the distribution is regenerated.
add_file()
Add a $filename containing $content to the distribution.
$dist->add_file( $filename, $content );
remove_file()
Removes $filename from the distribution.
$dist->remove_file( $filename );
change_file()
Changes the contents of $filename to $content. No action is performed until the distribution is regenerated.
$dist->change_file( $filename, $content );
Properties
name()
Returns the name of the distribution.
dirname()
Returns the directory where the distribution is created.
$dist->dirname; # e.g. t/_tmp/Simple
Functions
undent()
Removes leading whitespace from a multi-line string according to the amount of whitespace on the first line.
my $string = undent(" foo(\n bar => 'baz'\n )");
$string eq "foo(
bar => 'baz'
)";