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;
2             # ABSTRACT: build fake dists for testing CPAN tools
3             $Module::Faker::VERSION = '0.022';
4 1     1   64765 use 5.008;
  1         14  
5 1     1   545 use Moose 0.33;
  1         454128  
  1         8  
6              
7 1     1   7985 use Module::Faker::Dist;
  1         4  
  1         10  
8              
9 1     1   666 use File::Next ();
  1         1968  
  1         327  
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 the 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 1475 my ($self) = @_;
132              
133 1         3 for (qw(source dest)) {
134 2         60 my $dir = $self->$_;
135 2 50       33 Carp::croak "$_ directory does not exist" unless -e $dir;
136 2 50       27 Carp::croak "$_ directory is not readable" unless -r $dir;
137             }
138              
139 1 50       27 Carp::croak "$_ directory is not writeable" unless -w $self->dest;
140             }
141              
142             sub make_fakes {
143 1     1 1 781 my ($class, $arg) = @_;
144              
145 1 50       16 my $self = ref $class ? $class : $class->new($arg);
146              
147 1         34 my $iter = File::Next::files($self->source);
148              
149 1         109 while (my $file = $iter->()) {
150 10         6674 my $dist = $self->dist_class->from_file($file);
151 10         370 $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         9  
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.022
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 METHODS
191              
192             =head2 make_fakes
193              
194             Module::Faker->make_fakes(\%arg);
195              
196             This method creates a new Module::Faker and builds archives in its destination
197             directory for every dist-describing file in its source directory. See the
198             L</new> method below.
199              
200             =head2 new
201              
202             my $faker = Module::Faker->new(\%arg);
203              
204             This create the new Module::Faker. All arguments may be accessed later by
205             methods of the same name. Valid arguments are:
206              
207             source - the directory in which to find source files
208             dest - the directory in which to construct dist archives
209              
210             dist_class - the class used to fake dists; default: Module::Faker::Dist
211              
212             The source files are essentially a subset of CPAN::Meta files with some
213             optional extra features. All the you really require are the name and
214             abstract. Other bits like requirements can be specified and will be passed
215             through. Out of the box the module will create the main module file based
216             on the module name and a single test file. You can either use the provides
217             section of the CPAN::META file or to specify their contents use the
218             X_Module_Faker append section.
219              
220             The X_Module_Faker also allows you to alter the cpan_author from the
221             default 'LOCAL <LOCAL@cpan.local>' which overrides whatever is in the
222             usual CPAN::Meta file.
223              
224             Here is an example yaml specification from the tests,
225              
226             name: Append
227             abstract: nothing to see here
228             provides:
229             Provides::Inner:
230             file: lib/Provides/Inner.pm
231             version: 0.001
232             Provides::Inner::Util:
233             file: lib/Provides/Inner.pm
234             X_Module_Faker:
235             cpan_author: SOMEONE
236             append:
237             - file: lib/Provides/Inner.pm
238             content: "\n=head1 NAME\n\nAppend - here I am"
239             - file: t/foo.t
240             content: |
241             use Test::More;
242             - file: t/foo.t
243             content: "ok(1);"
244              
245             If you need to sort the packages within a file you
246             can use an X_Module_Faker:order parameter on the
247             provides class.
248              
249             provides:
250             Provides::Inner::Sorted::Charlie:
251             file: lib/Provides/Inner/Sorted.pm
252             version: 0.008
253             X_Module_Faker:
254             order: 2
255             Provides::Inner::Sorted::Alfa:
256             file: lib/Provides/Inner/Sorted.pm
257             version: 0.001
258             X_Module_Faker:
259             order: 1
260              
261             The supported keys from CPAN::Meta are,
262              
263             =over
264              
265             =item * abstract
266              
267             =item * license
268              
269             =item * name
270              
271             =item * release_status
272              
273             =item * version
274              
275             =item * provides
276              
277             =item * prereqs
278              
279             =item * x_authority
280              
281             =back
282              
283             =head1 AUTHOR
284              
285             Ricardo Signes <rjbs@cpan.org>
286              
287             =head1 CONTRIBUTORS
288              
289             =for stopwords Colin Newell David Golden Steinbrunner Jeffrey Ryan Thalhammer Moritz Onken Randy Stauner
290              
291             =over 4
292              
293             =item *
294              
295             Colin Newell <colin.newell@gmail.com>
296              
297             =item *
298              
299             David Golden <dagolden@cpan.org>
300              
301             =item *
302              
303             David Steinbrunner <dsteinbrunner@pobox.com>
304              
305             =item *
306              
307             Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
308              
309             =item *
310              
311             Moritz Onken <onken@netcubed.de>
312              
313             =item *
314              
315             Randy Stauner <randy@magnificent-tears.com>
316              
317             =back
318              
319             =head1 COPYRIGHT AND LICENSE
320              
321             This software is copyright (c) 2008 by Ricardo Signes.
322              
323             This is free software; you can redistribute it and/or modify it under
324             the same terms as the Perl 5 programming language system itself.
325              
326             =cut