File Coverage

blib/lib/Module/Faker.pm
Criterion Covered Total %
statement 26 26 100.0
branch 4 8 50.0
condition n/a
subroutine 7 7 100.0
pod 1 2 50.0
total 38 43 88.3


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