Codebase list libmodule-faker-perl / e25a8fe
refactoring, updates for CPAN-Faker Ricardo SIGNES 16 years ago
2 changed file(s) with 42 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
00
1 ExtUtils-FakeMaker contains tools for building fake CPAN distributions for
2 testing. For more information, consult the inline POD (documentation).
1 Module-Faker contains tools for building fake CPAN distributions for testing.
2 For more information, consult the inline POD (documentation).
33
1717 has name => (is => 'ro', isa => 'Str', required => 1);
1818 has version => (is => 'ro', isa => 'Maybe[Str]', default => '0.01');
1919 has abstract => (is => 'ro', isa => 'Str', default => 'a great new dist');
20 has cpan_author => (is => 'ro', isa => 'Maybe[Str]', default => 'LOCAL');
2021 has archive_ext => (is => 'ro', isa => 'Str', default => 'tar.gz');
2122
2223 has archive_basename => (
8889 return @modules;
8990 }
9091
92 sub _mk_container_path {
93 my ($self, $filename) = @_;
94
95 my (@parts) = File::Spec->splitdir($filename);
96 my $leaf_filename = pop @parts;
97 File::Path::mkpath(File::Spec->catdir(@parts));
98 }
99
91100 sub make_dist_dir {
92101 my ($self, $arg) = @_;
93102 $arg ||= {};
97106
98107 for my $file ($self->files) {
99108 my $fqfn = File::Spec->catfile($dist_dir, $file->filename);
100 my (@parts) = File::Spec->splitdir($fqfn);
101 my $leaf_filename = pop @parts;
102 File::Path::mkpath(File::Spec->catdir(@parts));
109 $self->_mk_container_path($fqfn);
110
103111 open my $fh, '>', $fqfn or die "couldn't open $fqfn for writing: $!";
104112 print $fh $file->as_string;
105113 close $fh or die "error when closing $fqfn: $!";
108116 return $dist_dir;
109117 }
110118
119 sub _author_dir_infix {
120 my ($self) = @_;
121
122 Carp::croak "can't put archive in author dir with no author defined"
123 unless my $pauseid = $self->cpan_author;
124
125 # Sorta like pow- pow- power-wheels! -- rjbs, 2008-03-14
126 my ($pa, $p) = $pauseid =~ /^((.).)/;
127 return ($p, $pa, $pauseid);
128 }
129
130 sub archive_filename {
131 my ($self, $arg) = @_;
132
133 my $base = $self->archive_basename;
134 my $ext = $self->archive_ext;
135
136 return File::Spec->catfile(
137 ($arg->{author_prefix} ? $self->_author_dir_infix : ()),
138 "$base.$ext",
139 );
140 }
141
111142 sub make_archive {
112143 my ($self, $arg) = @_;
113144 $arg ||= {};
116147
117148 my $archive = Archive::Any::Create->new;
118149 my $container = $self->archive_basename;
119 my $ext = $self->archive_ext;
120150
121151 $archive->container($container);
122152
124154 $archive->add_file($file->filename, $file->as_string);
125155 }
126156
127 my $archive_filename = File::Spec->catfile($dir, "$container.$ext");
157 my $archive_filename = File::Spec->catfile(
158 $dir,
159 $self->archive_filename({ author_prefix => $arg->{author_prefix} })
160 );
161
162 $self->_mk_container_path($archive_filename);
128163 $archive->write_file($archive_filename);
129164
130165 return $archive_filename;