| 1 | package Module::Faker 0.027; | ||||||||||
| 2 | # ABSTRACT: build fake dists for testing CPAN tools | ||||||||||
| 3 | |||||||||||
| 4 | 1 | ▶ | use v5.20.0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Moose 0.33; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | use Module::Faker::Dist; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 1 | ▶ | use File::Next (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 1 | has source => (is => 'ro', required => 1); | |||||||||
| 120 | 1 | has dest => (is => 'ro', required => 1); | |||||||||
| 121 | 1 | has author_prefix => (is => 'ro', default => 0); | |||||||||
| 122 | |||||||||||
| 123 | has dist_class => ( | ||||||||||
| 124 | is => 'ro', | ||||||||||
| 125 | isa => 'Str', | ||||||||||
| 126 | required => 1, | ||||||||||
| 127 | 1 | ▶ | default => sub { 'Module::Faker::Dist' }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 128 | 1 | ); | |||||||||
| 129 | |||||||||||
| 130 | 1 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: called CC=5 SCAR=16.8
Pod
undocumented
| |||||||||||
| 131 | 1 | my ($self) = @_; | |||||||||
| 132 | |||||||||||
| 133 | 1 | for (qw(source dest)) { | |||||||||
| 134 | 2 | my $dir = $self->$_; | |||||||||
| 135 | 2 | ▶ | Carp::croak "$_ directory does not exist" unless -e $dir; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 136 | 2 | ▶ | Carp::croak "$_ directory is not readable" unless -r $dir; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 137 | } | ||||||||||
| 138 | |||||||||||
| 139 | 1 | ▶ | Carp::croak "$_ directory is not writeable" unless -w $self->dest; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 140 | } | ||||||||||
| 141 | |||||||||||
| 142 | 1 | ▶ | sub make_fakes { | ||||||||
|
Subroutine
make_fakes: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 143 | 1 | my ($class, $arg) = @_; | |||||||||
| 144 | |||||||||||
| 145 | 1 | ▶ | my $self = ref $class ? $class : $class->new($arg); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 146 | |||||||||||
| 147 | 1 | my $iter = File::Next::files($self->source); | |||||||||
| 148 | |||||||||||
| 149 | 1 | ▶ | while (my $file = $iter->()) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 150 | 11 | my $dist = $self->dist_class->from_file($file); | |||||||||
| 151 | 11 | $dist->make_archive({ | |||||||||
| 152 | dir => $self->dest, | ||||||||||
| 153 | author_prefix => $self->author_prefix, | ||||||||||
| 154 | }); | ||||||||||
| 155 | } | ||||||||||
| 156 | } | ||||||||||
| 157 | |||||||||||
| 158 | 1 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 159 | 1 | 1; | |||||||||
| 160 | |||||||||||
| 161 | __END__ | ||||||||||