Hmmm that didn't work for me. When I add printouts, it seem that the
presence or absence of [PodWeaver] changes which phase DZPST is run in.
The following works for me, though:
package Dist::Zilla::Plugin::ShareDir::Tarball;
BEGIN {
$Dist::Zilla::Plugin::ShareDir::Tarball::AUTHORITY = 'cpan:YANICK';
}
{
$Dist::Zilla::Plugin::ShareDir::Tarball::VERSION = '0.3.1';
}
# ABSTRACT: Bundle your shared dir into a tarball
use strict;
use warnings;
use Moose;
use Dist::Zilla::File::InMemory;
use Compress::Zlib;
use Archive::Tar;
has dir => (
is => 'ro',
isa => 'Str',
default => 'share',
);
has archive => (
is => 'ro',
lazy => 1,
predicate => 'has_archive',
default => sub {
Archive::Tar->new;
},
);
has sharedir_checked => (
is => 'rw',
lazy => 1,
isa => 'Bool',
default => 0,
);
has shared_files => (
is => 'rw',
lazy => 1,
isa => 'ArrayRef[Dist::Zilla::File::OnDisk]',
default => sub { [] },
);
has share_dir_map => (
is => 'ro',
lazy => 1,
default => sub {
my $self = shift;
print "checking for share dir!\n";
if(not $self->sharedir_checked){
$self->check_sharedir;
}
return {} unless @{$self->shared_files};
print "had a share dir!\n";
return { dist => $self->dir };
},
);
sub compressed_archive {
Compress::Zlib::memGzip($_[0]->archive->write)
}
sub find_files {
my $self = shift;
my $dir = $self->dir . '/';
return grep { print 'index of ' . $_->name . ' in ' . "$dir is " .
(!index $_->name, $dir) . "\n"; !index $_->name, $dir } @{ $self->zilla-
Show quoted text>files };
}
sub check_sharedir {
my $self = shift;
my @shared = $self->find_files;
# $self->sharedir_checked(1);
$self->shared_files(\@shared);
$self->sharedir_checked(1);
}
sub munge_files {
my( $self ) = @_;
$self->check_sharedir
unless $self->sharedir_checked;
my $src = $self->dir;
my @shared = @{$self->shared_files} or return;
for ( @shared ) {
( my $archive_name = $_->name ) =~ s#$src/##;
$self->archive->add_data( $archive_name => $_->content );
$self->zilla->prune_file($_);
}
$self->add_file( Dist::Zilla::File::InMemory->new(
name => 'share/shared-files.tar.gz',
content => $self->compressed_archive,
));
print "munge files got here\n";
}
with 'Dist::Zilla::Role::ShareDir',
'Dist::Zilla::Role::FileInjector',
'Dist::Zilla::Role::FileMunger';
1;
I've never used Moose before, so maybe it could use a fixup. There's
also a little bit of printing cruft I used for debugging.
But basically it will check if files have been searched for yet, and if
not it will search for them. It checks this at any phase (munge files or
sharedir phases) and saves the search result so you don't have to search
twice.
On my machine, at least, it doesn't matter if the found files have
contents or not; they just need to exist.
On Sun Mar 10 12:11:19 2013, yanick@babyl.dyndns.org wrote:
Show quoted text> On 13-03-09 11:56 PM, Nathan Gary Glenn via RT wrote:
> > Alright, I narrowed it down and it may or may not be your problem
> > (though it really may need documentation). I'm uploading an example.
>
> Excellent. Mucho thanks, having a concrete example to poke at
really
Show quoted text> makes things easier.
>
> > If [PodWeaver] is removed, or is used after [ShareDir::Tarball],
then it
Show quoted text> > works fine. Otherwise, no share directory is created.
>
> Aaaand I think I know why it does what it does in this case. The
shared
Show quoted text> abc/xyz directory only contains an empty file. Put something,
anything,
Show quoted text> in that file, and *pop!*, your shared tarball is going to appear.
>
> `/.
>
>
>