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.023;
2             # ABSTRACT: build fake dists for testing CPAN tools
3              
4 1     1   69587 use 5.008;
  1         13  
5 1     1   643 use Moose 0.33;
  1         477051  
  1         11  
6              
7 1     1   9226 use Module::Faker::Dist;
  1         4  
  1         10  
8              
9 1     1   608 use File::Next ();
  1         2105  
  1         298  
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 1200 my ($self) = @_;
132              
133 1         3 for (qw(source dest)) {
134 2         62 my $dir = $self->$_;
135 2 50       31 Carp::croak "$_ directory does not exist" unless -e $dir;
136 2 50       29 Carp::croak "$_ directory is not readable" unless -r $dir;
137             }
138              
139 1 50       29 Carp::croak "$_ directory is not writeable" unless -w $self->dest;
140             }
141              
142             sub make_fakes {
143 1     1 1 803 my ($class, $arg) = @_;
144              
145 1 50       16 my $self = ref $class ? $class : $class->new($arg);
146              
147 1         43 my $iter = File::Next::files($self->source);
148              
149 1         129 while (my $file = $iter->()) {
150 10         6913 my $dist = $self->dist_class->from_file($file);
151 10         372 $dist->make_archive({
152             dir => $self->dest,
153             author_prefix => $self->author_prefix,
154             });
155             }
156             }
157              
158 1     1   8 no Moose;
  1         3  
  1         8  
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.023
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 released
194             in the last two to three years. (That is, if the most recently released
195             version is v5.40, then this module should work on both v5.40 and v5.38.)
196              
197             Although it may work on older versions of perl, no guarantee is made that the
198             minimum required version will not be increased. The version may be increased
199             for any reason, and there is no promise that patches will be accepted to lower
200             the minimum required perl.
201              
202             =head1 METHODS
203              
204             =head2 make_fakes
205              
206             Module::Faker->make_fakes(\%arg);
207              
208             This method creates a new Module::Faker and builds archives in its destination
209             directory for every dist-describing file in its source directory. See the
210             L</new> method below.
211              
212             =head2 new
213              
214             my $faker = Module::Faker->new(\%arg);
215              
216             This create the new Module::Faker. All arguments may be accessed later by
217             methods of the same name. Valid arguments are:
218              
219             source - the directory in which to find source files
220             dest - the directory in which to construct dist archives
221              
222             dist_class - the class used to fake dists; default: Module::Faker::Dist
223              
224             The source files are essentially a subset of CPAN::Meta files with some
225             optional extra features. All you really require are the name and
226             abstract. Other bits like requirements can be specified and will be passed
227             through. Out of the box the module will create the main module file based
228             on the module name and a single test file. You can either use the provides
229             section of the CPAN::META file or to specify their contents use the
230             X_Module_Faker append section.
231              
232             The X_Module_Faker also allows you to alter the cpan_author from the
233             default 'LOCAL <LOCAL@cpan.local>' which overrides whatever is in the
234             usual CPAN::Meta file.
235              
236             Here is an example yaml specification from the tests,
237              
238             name: Append
239             abstract: nothing to see here
240             provides:
241             Provides::Inner:
242             file: lib/Provides/Inner.pm
243             version: 0.001
244             Provides::Inner::Util:
245             file: lib/Provides/Inner.pm
246             X_Module_Faker:
247             cpan_author: SOMEONE
248             append:
249             - file: lib/Provides/Inner.pm
250             content: "\n=head1 NAME\n\nAppend - here I am"
251             - file: t/foo.t
252             content: |
253             use Test::More;
254             - file: t/foo.t
255             content: "ok(1);"
256              
257             If you need to sort the packages within a file you
258             can use an X_Module_Faker:order parameter on the
259             provides class.
260              
261             provides:
262             Provides::Inner::Sorted::Charlie:
263             file: lib/Provides/Inner/Sorted.pm
264             version: 0.008
265             X_Module_Faker:
266             order: 2
267             Provides::Inner::Sorted::Alfa:
268             file: lib/Provides/Inner/Sorted.pm
269             version: 0.001
270             X_Module_Faker:
271             order: 1
272              
273             The supported keys from CPAN::Meta are,
274              
275             =over
276              
277             =item * abstract
278              
279             =item * license
280              
281             =item * name
282              
283             =item * release_status
284              
285             =item * version
286              
287             =item * provides
288              
289             =item * prereqs
290              
291             =item * x_authority
292              
293             =back
294              
295             =head1 AUTHOR
296              
297             Ricardo Signes <cpan@semiotic.systems>
298              
299             =head1 CONTRIBUTORS
300              
301             =for stopwords Colin Newell David Golden Steinbrunner gregor herrmann Jeffrey Ryan Thalhammer Mohammad S Anwar Moritz Onken Randy Stauner Ricardo Signes
302              
303             =over 4
304              
305             =item *
306              
307             Colin Newell <colin.newell@gmail.com>
308              
309             =item *
310              
311             David Golden <dagolden@cpan.org>
312              
313             =item *
314              
315             David Steinbrunner <dsteinbrunner@pobox.com>
316              
317             =item *
318              
319             gregor herrmann <gregoa@debian.org>
320              
321             =item *
322              
323             Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
324              
325             =item *
326              
327             Mohammad S Anwar <mohammad.anwar@yahoo.com>
328              
329             =item *
330              
331             Moritz Onken <onken@netcubed.de>
332              
333             =item *
334              
335             Randy Stauner <randy@magnificent-tears.com>
336              
337             =item *
338              
339             Ricardo Signes <rjbs@semiotic.systems>
340              
341             =item *
342              
343             Ricardo Signes <rjbs@users.noreply.github.com>
344              
345             =back
346              
347             =head1 COPYRIGHT AND LICENSE
348              
349             This software is copyright (c) 2008 by Ricardo Signes.
350              
351             This is free software; you can redistribute it and/or modify it under
352             the same terms as the Perl 5 programming language system itself.
353              
354             =cut