1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
|
package Module::Faker 0.027;
# ABSTRACT: build fake dists for testing CPAN tools
use v5.20.0;
use Moose 0.33;
use Module::Faker::Dist;
use File::Next ();
#pod =head1 SYNOPSIS
#pod
#pod Module::Faker->make_fakes({
#pod source => './dir-of-specs', # ...or a single file
#pod dest => './will-contain-tarballs',
#pod });
#pod
#pod =head2 DESCRIPTION
#pod
#pod Module::Faker is a tool for building fake CPAN modules and, perhaps more
#pod importantly, fake CPAN distributions. These are useful for running tools that
#pod operate against CPAN distributions without having to use real CPAN
#pod distributions. This is much more useful when testing an entire CPAN instance,
#pod rather than a single distribution, for which see L<CPAN::Faker|CPAN::Faker>.
#pod
#pod =method make_fakes
#pod
#pod Module::Faker->make_fakes(\%arg);
#pod
#pod This method creates a new Module::Faker and builds archives in its destination
#pod directory for every dist-describing file in its source directory. See the
#pod L</new> method below.
#pod
#pod =method new
#pod
#pod my $faker = Module::Faker->new(\%arg);
#pod
#pod This create the new Module::Faker. All arguments may be accessed later by
#pod methods of the same name. Valid arguments are:
#pod
#pod source - the directory in which to find source files
#pod dest - the directory in which to construct dist archives
#pod
#pod dist_class - the class used to fake dists; default: Module::Faker::Dist
#pod
#pod The source files are essentially a subset of CPAN::Meta files with some
#pod optional extra features. All you really require are the name and
#pod abstract. Other bits like requirements can be specified and will be passed
#pod through. Out of the box the module will create the main module file based
#pod on the module name and a single test file. You can either use the provides
#pod section of the CPAN::META file or to specify their contents use the
#pod X_Module_Faker append section.
#pod
#pod The X_Module_Faker also allows you to alter the cpan_author from the
#pod default 'LOCAL <LOCAL@cpan.local>' which overrides whatever is in the
#pod usual CPAN::Meta file.
#pod
#pod Here is an example yaml specification from the tests,
#pod
#pod name: Append
#pod abstract: nothing to see here
#pod provides:
#pod Provides::Inner:
#pod file: lib/Provides/Inner.pm
#pod version: 0.001
#pod Provides::Inner::Util:
#pod file: lib/Provides/Inner.pm
#pod X_Module_Faker:
#pod cpan_author: SOMEONE
#pod append:
#pod - file: lib/Provides/Inner.pm
#pod content: "\n=head1 NAME\n\nAppend - here I am"
#pod - file: t/foo.t
#pod content: |
#pod use Test::More;
#pod - file: t/foo.t
#pod content: "ok(1);"
#pod
#pod If you need to sort the packages within a file you
#pod can use an X_Module_Faker:order parameter on the
#pod provides class.
#pod
#pod provides:
#pod Provides::Inner::Sorted::Charlie:
#pod file: lib/Provides/Inner/Sorted.pm
#pod version: 0.008
#pod X_Module_Faker:
#pod order: 2
#pod Provides::Inner::Sorted::Alfa:
#pod file: lib/Provides/Inner/Sorted.pm
#pod version: 0.001
#pod X_Module_Faker:
#pod order: 1
#pod
#pod The supported keys from CPAN::Meta are,
#pod
#pod =over
#pod
#pod =item * abstract
#pod
#pod =item * license
#pod
#pod =item * name
#pod
#pod =item * release_status
#pod
#pod =item * version
#pod
#pod =item * provides
#pod
#pod =item * prereqs
#pod
#pod =item * x_authority
#pod
#pod =back
#pod
#pod =cut
has source => (is => 'ro', required => 1);
has dest => (is => 'ro', required => 1);
has author_prefix => (is => 'ro', default => 0);
has dist_class => (
is => 'ro',
isa => 'Str',
required => 1,
default => sub { 'Module::Faker::Dist' },
);
sub BUILD {
my ($self) = @_;
for (qw(source dest)) {
my $dir = $self->$_;
Carp::croak "$_ directory does not exist" unless -e $dir;
Carp::croak "$_ directory is not readable" unless -r $dir;
}
Carp::croak "$_ directory is not writeable" unless -w $self->dest;
}
sub make_fakes {
my ($class, $arg) = @_;
my $self = ref $class ? $class : $class->new($arg);
my $iter = File::Next::files($self->source);
while (my $file = $iter->()) {
my $dist = $self->dist_class->from_file($file);
$dist->make_archive({
dir => $self->dest,
author_prefix => $self->author_prefix,
});
}
}
no Moose;
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Module::Faker - build fake dists for testing CPAN tools
=head1 VERSION
version 0.027
=head1 SYNOPSIS
Module::Faker->make_fakes({
source => './dir-of-specs', # ...or a single file
dest => './will-contain-tarballs',
});
=head2 DESCRIPTION
Module::Faker is a tool for building fake CPAN modules and, perhaps more
importantly, fake CPAN distributions. These are useful for running tools that
operate against CPAN distributions without having to use real CPAN
distributions. This is much more useful when testing an entire CPAN instance,
rather than a single distribution, for which see L<CPAN::Faker|CPAN::Faker>.
=head1 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.
=head1 METHODS
=head2 make_fakes
Module::Faker->make_fakes(\%arg);
This method creates a new Module::Faker and builds archives in its destination
directory for every dist-describing file in its source directory. See the
L</new> method below.
=head2 new
my $faker = Module::Faker->new(\%arg);
This create the new Module::Faker. All arguments may be accessed later by
methods of the same name. Valid arguments are:
source - the directory in which to find source files
dest - the directory in which to construct dist archives
dist_class - the class used to fake dists; default: Module::Faker::Dist
The source files are essentially a subset of CPAN::Meta files with some
optional extra features. All you really require are the name and
abstract. Other bits like requirements can be specified and will be passed
through. Out of the box the module will create the main module file based
on the module name and a single test file. You can either use the provides
section of the CPAN::META file or to specify their contents use the
X_Module_Faker append section.
The X_Module_Faker also allows you to alter the cpan_author from the
default 'LOCAL <LOCAL@cpan.local>' which overrides whatever is in the
usual CPAN::Meta file.
Here is an example yaml specification from the tests,
name: Append
abstract: nothing to see here
provides:
Provides::Inner:
file: lib/Provides/Inner.pm
version: 0.001
Provides::Inner::Util:
file: lib/Provides/Inner.pm
X_Module_Faker:
cpan_author: SOMEONE
append:
- file: lib/Provides/Inner.pm
content: "\n=head1 NAME\n\nAppend - here I am"
- file: t/foo.t
content: |
use Test::More;
- file: t/foo.t
content: "ok(1);"
If you need to sort the packages within a file you
can use an X_Module_Faker:order parameter on the
provides class.
provides:
Provides::Inner::Sorted::Charlie:
file: lib/Provides/Inner/Sorted.pm
version: 0.008
X_Module_Faker:
order: 2
Provides::Inner::Sorted::Alfa:
file: lib/Provides/Inner/Sorted.pm
version: 0.001
X_Module_Faker:
order: 1
The supported keys from CPAN::Meta are,
=over
=item * abstract
=item * license
=item * name
=item * release_status
=item * version
=item * provides
=item * prereqs
=item * x_authority
=back
=head1 AUTHOR
Ricardo Signes <cpan@semiotic.systems>
=head1 CONTRIBUTORS
=for stopwords Colin Newell David Golden Steinbrunner gregor herrmann Jeffrey Ryan Thalhammer Mohammad S Anwar Moritz Onken Randy Stauner Ricardo Signes
=over 4
=item *
Colin Newell <colin.newell@gmail.com>
=item *
David Golden <dagolden@cpan.org>
=item *
David Steinbrunner <dsteinbrunner@pobox.com>
=item *
gregor herrmann <gregoa@debian.org>
=item *
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
=item *
Mohammad S Anwar <mohammad.anwar@yahoo.com>
=item *
Moritz Onken <onken@netcubed.de>
=item *
Randy Stauner <randy@magnificent-tears.com>
=item *
Ricardo Signes <rjbs@semiotic.systems>
=back
=head1 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.
=cut
|